From f6a33095358a64ebaad60c092c234c49ae2d6577 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Mon, 16 Feb 2009 15:58:31 +0100 Subject: [PATCH] hdt: Removing static dmitable, it have to be in the s_dmi structure Making dmi_iterate quieter Relocating hdt' submenus --- com32/include/dmi/dmi.h | 8 ++++-- com32/modules/Makefile | 2 +- com32/modules/dmi.c | 50 ++++++++++++++++++++---------------- com32/modules/dmitest.c | 11 +++++--- sample/hdt.c | 68 +++++++++++++++++++++++++++++-------------------- 5 files changed, 84 insertions(+), 55 deletions(-) diff --git a/com32/include/dmi/dmi.h b/com32/include/dmi/dmi.h index de177c1..d7425e9 100644 --- a/com32/include/dmi/dmi.h +++ b/com32/include/dmi/dmi.h @@ -30,6 +30,8 @@ static const char *bad_index = ""; #define DWORD(x) (u32)(*(const u32 *)(x)) #define QWORD(x) (*(const u64 *)(x)) +enum {DMI_TABLE_PRESENT = 100, ENODMITABLE}; + #include "dmi_bios.h" #include "dmi_system.h" #include "dmi_base_board.h" @@ -46,9 +48,10 @@ u16 num; u16 len; u16 ver; u32 base; +u16 major_version; +u16 minor_version; } dmi_table; -static dmi_table dmitable; struct dmi_header @@ -68,6 +71,7 @@ typedef struct { s_battery battery; s_memory memory[32]; int memory_count; + dmi_table dmitable; } s_dmi; void to_dmi_header(struct dmi_header *h, u8 *data); @@ -76,7 +80,7 @@ const char *dmi_string(struct dmi_header *dm, u8 s); inline int dmi_checksum(u8 *buf); void parse_dmitable(s_dmi *dmi); void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi); -int dmi_iterate(); +int dmi_iterate(s_dmi *dmi); /* dmi_utils.c */ void display_bios_characteristics(s_dmi *dmi); diff --git a/com32/modules/Makefile b/com32/modules/Makefile index 930e89b..1108e65 100644 --- a/com32/modules/Makefile +++ b/com32/modules/Makefile @@ -32,7 +32,7 @@ pcitest.elf : pcitest.o $(LIBS) $(C_LIBS) cpuidtest.elf : cpuidtest.o cpuid.o $(LIBS) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ -dmitest.elf : dmitest.o dmi_utils.o dmi.o $(LIBS) $(C_LIBS) +dmitest.elf : dmi.o dmitest.o dmi_utils.o $(LIBS) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ ethersel.elf : ethersel.o $(LIBS) $(C_LIBS) diff --git a/com32/modules/dmi.c b/com32/modules/dmi.c index 7d33a77..e68c73c 100644 --- a/com32/modules/dmi.c +++ b/com32/modules/dmi.c @@ -313,36 +313,42 @@ inline int dmi_checksum(u8 *buf) return (sum==0); } -int dmi_iterate() { +int dmi_iterate(s_dmi *dmi) { u8 buf[16]; char *p,*q; p=(char *)0xF0000; /* The start address to look at the dmi table */ for (q = p; q < p + 0x10000; q += 16) { memcpy(buf, q, 15); if(memcmp(buf, "_DMI_", 5)==0 && dmi_checksum(buf)) { - dmitable.num = buf[13]<<8|buf[12]; - dmitable.len = buf[7]<<8|buf[6]; - dmitable.base = buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8]; - dmitable.ver = (buf[0x06]<<8)+buf[0x07]; + dmi->dmitable.num = buf[13]<<8|buf[12]; + dmi->dmitable.len = buf[7]<<8|buf[6]; + dmi->dmitable.base = buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8]; + dmi->dmitable.ver = (buf[0x06]<<8)+buf[0x07]; /* * DMI version 0.0 means that the real version is taken from * the SMBIOS version, which we don't know at this point. */ - if(buf[14]!=0) - printf("DMI %d.%d present.\n",buf[14]>>4, buf[14]&0x0F); - else - printf("DMI present.\n"); + if(buf[14]!=0) { + dmi->dmitable.major_version=buf[14]>>4; + dmi->dmitable.minor_version=buf[14]&0x0F; + } + else { + dmi->dmitable.major_version=0; + dmi->dmitable.minor_version=0; + + } +/* printf("DMI present (version %d.%d)\n", dmitable.major_version,dmitable.minor_version); printf("%d structures occupying %d bytes.\n",dmitable.num, dmitable.len); - printf("DMI table at 0x%08X.\n",dmitable.base); - return 1; + printf("DMI table at 0x%08X.\n",dmitable.base);*/ + return DMI_TABLE_PRESENT; } } - dmitable.base=0; - dmitable.num=0; - dmitable.ver=0; - dmitable.len=0; - return 0; + dmi->dmitable.base=0; + dmi->dmitable.num=0; + dmi->dmitable.ver=0; + dmi->dmitable.len=0; + return -ENODMITABLE; } void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi) @@ -522,12 +528,12 @@ void dmi_decode(struct dmi_header *h, u16 ver, s_dmi *dmi) void parse_dmitable(s_dmi *dmi) { int i=0; u8 *data = NULL; - u8 buf[dmitable.len]; + u8 buf[dmi->dmitable.len]; - memcpy(buf,(int *)dmitable.base,sizeof(u8) * dmitable.len); + memcpy(buf,(int *)dmi->dmitable.base,sizeof(u8) * dmi->dmitable.len); data=buf; dmi->memory_count=0; - while(idmitable.num && data+4<=buf+dmi->dmitable.len) /* 4 is the length of an SMBIOS structure header */ { u8 *next; struct dmi_header h; to_dmi_header(&h, data); @@ -548,12 +554,12 @@ void parse_dmitable(s_dmi *dmi) { /* loo for the next handle */ next=data+h.length; - while(next-buf+1dmitable.len && (next[0]!=0 || next[1]!=0)) next++; next+=2; - if(next-buf<=dmitable.len) + if(next-buf<=dmi->dmitable.len) { - dmi_decode(&h, dmitable.ver,dmi); + dmi_decode(&h, dmi->dmitable.ver,dmi); } data=next; i++; diff --git a/com32/modules/dmitest.c b/com32/modules/dmitest.c index 0c82197..07febc5 100644 --- a/com32/modules/dmitest.c +++ b/com32/modules/dmitest.c @@ -164,11 +164,16 @@ int main(void) s_dmi dmi; openconsole(&dev_stdcon_r, &dev_stdcon_w); - if ( ! dmi_iterate() ) { - printf("No DMI Structure found\n"); - return -1; + if (dmi_iterate(&dmi) == -ENODMITABLE) { + printf("No DMI Structure found\n"); + return -1; + } else { + printf("DMI %d.%d present.\n",dmi.dmitable.major_version,dmi.dmitable.minor_version); + printf("%d structures occupying %d bytes.\n",dmi.dmitable.num, dmi.dmitable.len); + printf("DMI table at 0x%08X.\n",dmi.dmitable.base); } + parse_dmitable(&dmi); for (;;) { diff --git a/sample/hdt.c b/sample/hdt.c index afaeaa9..56f5dfd 100644 --- a/sample/hdt.c +++ b/sample/hdt.c @@ -56,6 +56,9 @@ #define WITH_PCI 1 #define WITH_MENU_DISPLAY 1 +#define SUBMENU_Y 3 +#define SUBMENU_X 29 + unsigned char MAIN_MENU, CPU_MENU, MOBO_MENU, CHASSIS_MENU, BIOS_MENU, SYSTEM_MENU, PCI_MENU, KERNEL_MENU; unsigned char MEMORY_MENU, MEMORY_SUBMENU[32], DISK_MENU, DISK_SUBMENU[32], PCI_SUBMENU[128],BATTERY_MENU; unsigned char SYSLINUX_MENU, ABOUT_MENU; @@ -403,9 +406,9 @@ return 0; /* Detecting if a DMI table exist * if yes, let's parse it */ int detect_dmi(s_dmi *dmi) { - if ( ! dmi_iterate() ) { + if (dmi_iterate(dmi) == -ENODMITABLE ) { printf("No DMI Structure found\n"); - return -1; + return -ENODMITABLE; } parse_dmitable(dmi); @@ -430,7 +433,7 @@ void compute_pci_device(unsigned char *menu,struct pci_device *pci_device,int pc *menu = add_menu(" Details ",-1); menu_count++; - set_menu_pos(7,17); + set_menu_pos(5,17); snprintf(buffer,sizeof buffer,"Vendor : %s",pci_device->dev_info->vendor_name); snprintf(statbuffer,sizeof statbuffer,"Vendor Name: %s",pci_device->dev_info->vendor_name); @@ -518,12 +521,12 @@ void compute_KERNEL(unsigned char *menu,struct pci_domain **pci_domain) { char buffer[SUBMENULEN+1]; char infobar[STATLEN+1]; char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + struct pci_device *pci_device; *menu = add_menu(" Kernel Modules ",-1); menu_count++; printf("MENU: Computing Kernel menu\n"); - set_menu_pos(4,29); - struct pci_device *pci_device; + set_menu_pos(SUBMENU_Y,SUBMENU_X); if (modules_pcimap == -ENOMODULESPCIMAP) { add_item("The modules.pcimap file is missing","Missing modules.pcimap file",OPT_INACTIVE,NULL,0); @@ -562,7 +565,8 @@ void compute_battery(unsigned char *menu, s_dmi *dmi) { *menu = add_menu(" Battery ",-1); menu_count++; printf("MENU: Computing Battery menu\n"); - set_menu_pos(4,29); + set_menu_pos(SUBMENU_Y,SUBMENU_X); + snprintf(buffer, sizeof buffer,"Vendor : %s",dmi->battery.manufacturer); snprintf(statbuffer, sizeof statbuffer,"Vendor: %s",dmi->battery.manufacturer); add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); @@ -777,7 +781,7 @@ void compute_motherboard(unsigned char *menu,s_dmi *dmi) { printf("MENU: Computing motherboard menu\n"); *menu = add_menu(" Motherboard ",-1); menu_count++; - set_menu_pos(4,29); + set_menu_pos(SUBMENU_Y,SUBMENU_X); snprintf(buffer,sizeof buffer,"Vendor : %s",dmi->base_board.manufacturer); snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",dmi->base_board.manufacturer); @@ -815,7 +819,7 @@ void compute_system(unsigned char *menu,s_dmi *dmi) { printf("MENU: Computing system menu\n"); *menu = add_menu(" System ",-1); menu_count++; - set_menu_pos(4,29); + set_menu_pos(SUBMENU_Y,SUBMENU_X); snprintf(buffer,sizeof buffer,"Vendor : %s",dmi->system.manufacturer); snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",dmi->system.manufacturer); @@ -857,7 +861,8 @@ void compute_chassis(unsigned char *menu,s_dmi *dmi) { printf("MENU: Computing chassis menu\n"); *menu = add_menu(" Chassis ",-1); menu_count++; - set_menu_pos(4,29); + set_menu_pos(SUBMENU_Y,SUBMENU_X); + snprintf(buffer,sizeof buffer,"Vendor : %s",dmi->chassis.manufacturer); snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",dmi->chassis.manufacturer); add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); @@ -890,7 +895,7 @@ void compute_bios(unsigned char *menu,s_dmi *dmi) { *menu = add_menu(" BIOS ",-1); menu_count++; printf("MENU: Computing BIOS menu\n"); - set_menu_pos(4,29); + set_menu_pos(SUBMENU_Y,SUBMENU_X); snprintf(buffer,sizeof buffer,"Vendor : %s",dmi->bios.vendor); snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",dmi->bios.vendor); @@ -922,6 +927,7 @@ void compute_processor(unsigned char *menu,s_cpu *cpu, s_dmi *dmi) { printf("MENU: Computing Processor menu\n"); *menu = add_menu(" Main Processor ",-1); menu_count++; + set_menu_pos(SUBMENU_Y,SUBMENU_X); snprintf(buffer,sizeof buffer,"Vendor : %s",cpu->vendor); snprintf(statbuffer,sizeof statbuffer,"Vendor: %s",cpu->vendor); @@ -1082,9 +1088,11 @@ void detect_hardware(s_dmi *dmi, s_cpu *cpu, struct pci_domain **pci_domain, str detect_disks(disk_info); printf("DMI: Detecting Table\n"); - if (detect_dmi(dmi) == 0) + if (detect_dmi(dmi) ==0 ) is_dmi_valid=true; + printf("DMI: Table found ! (version %d.%d)\n",dmi->dmitable.major_version,dmi->dmitable.minor_version); + #ifdef WITH_PCI printf("PCI: Detecting Devices\n"); /* Scanning to detect pci buses and devices */ @@ -1155,7 +1163,9 @@ void compute_aboutmenu(unsigned char *menu) { *menu = add_menu(" About ",-1); menu_count++; - set_menu_pos(4,29); + set_menu_pos(SUBMENU_Y,SUBMENU_X); + + printf("MENU: About Syslinux menu\n"); snprintf(buffer, sizeof buffer, "Product : %s", PRODUCT_NAME); snprintf(statbuffer, sizeof statbuffer, "Product : %s", PRODUCT_NAME); @@ -1182,6 +1192,9 @@ void compute_syslinuxmenu(unsigned char *menu) { char buffer[SUBMENULEN+1]; char statbuffer[STATLEN+1]; const struct syslinux_version *sv; + + printf("MENU: Computing Syslinux menu\n"); + memset(syslinux_fs,0,sizeof syslinux_fs); memset(syslinux_fs_menu,0,sizeof syslinux_fs_menu); @@ -1197,7 +1210,7 @@ void compute_syslinuxmenu(unsigned char *menu) { snprintf(syslinux_fs_menu,sizeof syslinux_fs_menu," %s ",syslinux_fs); *menu = add_menu(syslinux_fs_menu,-1); menu_count++; - set_menu_pos(4,29); + set_menu_pos(SUBMENU_Y,SUBMENU_X); snprintf(buffer, sizeof buffer, "Bootloader : %s", syslinux_fs); snprintf(statbuffer, sizeof statbuffer, "Bootloader: %s", syslinux_fs); @@ -1215,10 +1228,11 @@ void compute_syslinuxmenu(unsigned char *menu) { snprintf(statbuffer, sizeof statbuffer, "Max API: %u",sv->max_api); add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); - snprintf(buffer, sizeof buffer, "Copyright :%s", sv->copyright_string); - snprintf(statbuffer, sizeof statbuffer, "Copyright:%s", sv->copyright_string); - add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); + add_item("","",OPT_SEP,"",0); + snprintf(buffer, sizeof buffer, "%s", sv->copyright_string+1); + snprintf(statbuffer, sizeof statbuffer, "%s", sv->copyright_string+1); + add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0); } /* Compute Main' Submenus*/ @@ -1250,25 +1264,25 @@ void compute_main_menu() { set_item_options(-1,24); #ifdef WITH_PCI - add_item("PCI evices","PCI Devices",OPT_SUBMENU,NULL,PCI_MENU); + add_item("PCI evices","PCI Devices Menu",OPT_SUBMENU,NULL,PCI_MENU); #endif if (nb_sub_disk_menu>0) - add_item("isks","Disks",OPT_SUBMENU,NULL,DISK_MENU); - add_item("emory Modules","Memory Modules",OPT_SUBMENU,NULL,MEMORY_MENU); - add_item("

rocessor","Main Processor",OPT_SUBMENU,NULL,CPU_MENU); + add_item("isks","Disks Menu",OPT_SUBMENU,NULL,DISK_MENU); + add_item("emory Modules","Memory Modules Menu",OPT_SUBMENU,NULL,MEMORY_MENU); + add_item("

rocessor","Main Processor Menu",OPT_SUBMENU,NULL,CPU_MENU); if (is_dmi_valid) { - add_item("otherboard","Motherboard",OPT_SUBMENU,NULL,MOBO_MENU); - add_item("ios","Bios",OPT_SUBMENU,NULL,BIOS_MENU); - add_item("hassis","Chassis",OPT_SUBMENU,NULL,CHASSIS_MENU); - add_item("ystem","System",OPT_SUBMENU,NULL,SYSTEM_MENU); - add_item("Batery","Battery",OPT_SUBMENU,NULL,BATTERY_MENU); + add_item("Mtherboard","Motherboard Menu",OPT_SUBMENU,NULL,MOBO_MENU); + add_item("ios","Bios Menu",OPT_SUBMENU,NULL,BIOS_MENU); + add_item("hassis","Chassis Menu",OPT_SUBMENU,NULL,CHASSIS_MENU); + add_item("ystem","System Menu",OPT_SUBMENU,NULL,SYSTEM_MENU); + add_item("Batery","Battery Menu",OPT_SUBMENU,NULL,BATTERY_MENU); } add_item("","",OPT_SEP,"",0); #ifdef WITH_PCI - add_item("ernel Modules","Kernel Modules",OPT_SUBMENU,NULL,KERNEL_MENU); + add_item("ernel Modules","Kernel Modules Menu",OPT_SUBMENU,NULL,KERNEL_MENU); #endif - add_item("yslinux","Syslinux Information",OPT_SUBMENU,NULL,SYSLINUX_MENU); + add_item("yslinux","Syslinux Information Menu",OPT_SUBMENU,NULL,SYSLINUX_MENU); add_item("bout","About Menu",OPT_SUBMENU,NULL,ABOUT_MENU); } -- 2.7.4