diff options
author | nima <nima@abc39116-655e-4be6-ad55-d661dc543056> | 2008-10-31 10:24:41 +0000 |
---|---|---|
committer | nima <nima@abc39116-655e-4be6-ad55-d661dc543056> | 2008-10-31 10:24:41 +0000 |
commit | 24f10bb094c9831f4133d488d0af90dc2a83590f (patch) | |
tree | 86331f5b15e595497dd753b38f113b21ab56b563 | |
parent | 34ed409541219e8239a5826849ef36d8f4a05eb9 (diff) | |
download | python-dmidecode-24f10bb094c9831f4133d488d0af90dc2a83590f.tar.gz python-dmidecode-24f10bb094c9831f4133d488d0af90dc2a83590f.tar.xz python-dmidecode-24f10bb094c9831f4133d488d0af90dc2a83590f.zip |
Cleanup.
git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@96 abc39116-655e-4be6-ad55-d661dc543056
-rw-r--r-- | Makefile | 161 | ||||
-rw-r--r-- | dmidecode.h | 3 | ||||
-rw-r--r-- | dmidecodebin.c | 39 | ||||
-rw-r--r-- | dmidecodemodule.c | 54 | ||||
-rw-r--r-- | dmidecodemodule.h | 2 | ||||
-rw-r--r-- | dmihelper.h | 1 | ||||
-rw-r--r-- | dmiopt.c | 318 | ||||
-rw-r--r-- | dmiopt.h | 48 | ||||
-rw-r--r-- | ownership.c | 212 | ||||
-rw-r--r-- | vpddecode.c | 202 | ||||
-rw-r--r-- | vpdopt.c | 157 | ||||
-rw-r--r-- | vpdopt.h | 45 |
12 files changed, 68 insertions, 1174 deletions
@@ -1,151 +1,62 @@ -# -# DMI Decode -# BIOS Decode -# -# (C) 2000-2002 Alan Cox <alan@redhat.com> -# (C) 2002-2007 Jean Delvare <khali@linux-fr.org> -# -# Licensed under the GNU Public License. -# - -#. TODO: mtrace, leaks check... etc. +#. +#. DMI Decode Python Module +#. +#. (C) 2008 Nima Talebi <nima@it.net.au> +#. +#. Licensed under the GNU Public License v3 +#. -#. Bug in python2.4 PyString_FromFormat that results in not interpreting printf style formatting with %u and %lu. -PY = $(shell python -V 2>&1 |sed -e 's/.\(ython\) \(2\.[0-9]\)\..*/p\1\2/') -#PY = python2.5 -CC = gcc +PY := $(shell python -V 2>&1 |sed -e 's/.\(ython\) \(2\.[0-9]\)\..*/p\1\2/') +CC := gcc +RM := rm -f -CFLAGS = -fno-strict-aliasing -D_XOPEN_SOURCE=600 -CFLAGS += -W -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Winline -Wundef #-Wcast-qual +CFLAGS = -D_XOPEN_SOURCE=600 +CFLAGS += -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Winline -Wundef #-Wcast-qual +CFLAGS += -pthread -fno-strict-aliasing -DNDEBUG -fPIC CFLAGS += -I/usr/include/$(PY) -#. +CFLAGS += -g -DNDEBUG +#CFLAGS += -O2 -DNDEBUG #CFLAGS += -DBIGENDIAN #CFLAGS += -DALIGNMENT_WORKAROUND -#. -#. When debugging, disable -O2 and enable -g. -CFLAGS += -g -#CFLAGS += -O2 -DNDEBUG - -SOFLAGS = -shared -fPIC - -# Pass linker flags here -#LDFLAGS = -I/usr/include/$(PY) -lefence -LDFLAGS = -I/usr/include/$(PY) -DESTDIR = -prefix = /usr/local -sbindir = $(prefix)/sbin -mandir = $(prefix)/share/man -man8dir = $(mandir)/man8 -docdir = $(prefix)/share/doc/dmidecode -INSTALL := install -INSTALL_DATA := $(INSTALL) -m 644 -INSTALL_DIR := $(INSTALL) -m 755 -d -INSTALL_PROGRAM := $(INSTALL) -m 755 -RM := rm -f - -PROGRAMS := dmidecode -PROGRAMS += $(shell test `uname -m 2>/dev/null` != ia64 && echo biosdecode ownership vpddecode) -# BSD make doesn't understand the $(shell) syntax above, it wants the != -# syntax below. GNU make ignores the line below so in the end both BSD -# make and GNU make are happy. -PROGRAMS != echo dmidecode ; test `uname -m 2>/dev/null` != ia64 && echo biosdecode ownership vpddecode - - -all : $(PROGRAMS) module - -module: - $(PY) setup.py build +#gcc -D_XOPEN_SOURCE=600 -W -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Winline -Wundef -pthread -fno-strict-aliasing -DNDEBUG -fPIC -I/usr/include/python2.4 -L. -g -DNDEBUG -lpython -c -lutil -lpython -o dmidecodemodule.o dmidecodemodule.c *.o +#gcc -pthread -shared -L/home/nima/dev-room/projects/dmidecode -lutil -o build/lib.linux-i686-2.4/dmidecode.so +LDFLAGS = -I/usr/include/$(PY) -lefence +SOFLAGS = -shared -fPIC -L/usr/include/$(PY) -L/home/nima/dev-room/projects/dmidecode -lutil # # Shared Objects # +libdmidecode.so: dmihelper.o util.o dmioem.o dmidecode.o dmidecodemodule.o + $(CC) $(LDFLAGS) $(SOFLAGS) $^ -o $@ + cp $@ /usr/lib/python2.4/site-packages/dmidecode.so -libdmidecode.so: dmidecode.o util.o - $(CC) $(LDFLAGS) $(SOFLAGS) $< -o $@ - -# -# Programs -# - -dmidecode: dmidecodebin.c dmihelper.o libdmidecode.so dmidecode.o dmiopt.o dmioem.o util.o - $(CC) $(LDFLAGS) $< -L. -ldmidecode -l$(PY) dmihelper.o dmidecode.o dmiopt.o dmioem.o util.o -o $@ - -biosdecode : biosdecode.o util.o - $(CC) $(LDFLAGS) biosdecode.o util.o -o $@ - -ownership : ownership.o util.o - $(CC) $(LDFLAGS) ownership.o util.o -o $@ - -vpddecode : vpddecode.o vpdopt.o util.o - $(CC) $(LDFLAGS) vpddecode.o vpdopt.o util.o -o $@ - -# -# Objects -# - -dmidecode.o : dmidecode.c version.h types.h util.h config.h dmidecode.h dmiopt.h dmioem.h - $(CC) $(CFLAGS) -c $< -o $@ - -dmiopt.o : dmiopt.c config.h types.h util.h dmidecode.h dmiopt.h - $(CC) $(CFLAGS) -c $< -o $@ - -dmioem.o : dmioem.c types.h dmidecode.h dmioem.h - $(CC) $(CFLAGS) -c $< -o $@ - -biosdecode.o : biosdecode.c version.h types.h util.h config.h - $(CC) $(CFLAGS) -c $< -o $@ - -ownership.o : ownership.c version.h types.h util.h config.h - $(CC) $(CFLAGS) -c $< -o $@ +dmidecodemodule.o: dmidecodemodule.c #dmidecodemodule.h dmihelper.o util.o dmioem.o dmidecode.o + $(CC) $(CFLAGS) -c -o $@ $< #dmihelper.o util.o dmioem.o dmidecode.o -vpddecode.o : vpddecode.c version.h types.h util.h config.h vpdopt.h - $(CC) $(CFLAGS) -c $< -o $@ - -vpdopt.o : vpdopt.c config.h util.h vpdopt.h - $(CC) $(CFLAGS) -c $< -o $@ - -util.o : util.c types.h util.h config.h - $(CC) $(CFLAGS) -c $< -o $@ +dmidecode.o: dmidecode.c version.h types.h util.h config.h dmidecode.h dmioem.h + $(CC) $(CFLAGS) -c -o $@ $< dmihelper.o: dmihelper.c dmihelper.h - $(CC) $(CFLAGS) -c $< -o $@ - -# -# Commands -# - -strip : $(PROGRAMS) - strip $(PROGRAMS) + $(CC) $(CFLAGS) -c -o $@ $< -install : install-module install-bin install-man install-doc +util.o: util.c types.h util.h config.h + $(CC) $(CFLAGS) -c -o $@ $< -uninstall : uninstall-bin uninstall-man uninstall-doc +dmioem.o: dmioem.c types.h dmidecode.h dmioem.h + $(CC) $(CFLAGS) -c -o $@ $< -install-bin : $(PROGRAMS) - $(INSTALL_DIR) $(DESTDIR)$(sbindir) - for program in $(PROGRAMS) ; do \ - $(INSTALL_PROGRAM) $$program $(DESTDIR)$(sbindir) ; done - -uninstall-bin : - for program in $(PROGRAMS) ; do \ - $(RM) $(DESTDIR)$(sbindir)/$$program ; done - -install-man : - $(INSTALL_DIR) $(DESTDIR)$(man8dir) - for program in $(PROGRAMS) ; do \ - $(INSTALL_DATA) man/$$program.8 $(DESTDIR)$(man8dir) ; done - -uninstall-man : - for program in $(PROGRAMS) ; do \ - $(RM) $(DESTDIR)$(man8dir)/$$program.8 +dmidecodemodule: + $(PY) setup.py build -install-module: +install: $(PY) setup.py install +uninstall: + install-doc : $(INSTALL_DIR) $(DESTDIR)$(docdir) $(INSTALL_DATA) README $(DESTDIR)$(docdir) diff --git a/dmidecode.h b/dmidecode.h index 860f212..c8206cc 100644 --- a/dmidecode.h +++ b/dmidecode.h @@ -27,7 +27,6 @@ struct dmi_header { }; PyObject *dmi_dump(struct dmi_header *h); -//void dmi_decode(struct dmi_header *h, u16 ver, PyObject *pydata); PyObject* dmi_decode(struct dmi_header *h, u16 ver); int address_from_efi(size_t *address); void to_dmi_header(struct dmi_header *h, u8 *data); @@ -39,5 +38,3 @@ const char *dmi_system_uuid(u8 *p); PyObject *dmi_system_uuid_py(const u8 *p, u16 ver); const char *dmi_chassis_type(u8 code); int dmi_processor_frequency(const u8 *p); - -int submain(int argc, char * const argv[]); diff --git a/dmidecodebin.c b/dmidecodebin.c deleted file mode 100644 index 3b1a438..0000000 --- a/dmidecodebin.c +++ /dev/null @@ -1,39 +0,0 @@ -//. This file now produces the executable `dmidecode', and dynamically links -//. against libdmidecode.so. -#include <Python.h> - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> - -#include "version.h" -#include "config.h" -#include "types.h" -#include "util.h" -#include "dmidecode.h" -#include "dmiopt.h" -#include "dmioem.h" - -#define EFI_NOT_FOUND (-1) -#define EFI_NO_SMBIOS (-2) - -#include "dmihelper.h" - -extern const char *dmi_dump(struct dmi_header *h, char *_); -//extern void dmi_decode(struct dmi_header *h, u16 ver, PyObject *pydata); -extern PyObject *dmi_decode(struct dmi_header *h, u16 ver); -extern int address_from_efi(size_t *address, char *_); -extern void to_dmi_header(struct dmi_header *h, u8 *data); -extern void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem); -extern int smbios_decode(u8 *buf, const char *devmem, PyObject* pydata); -extern int legacy_decode(u8 *buf, const char *devmem, PyObject* pydata); -extern int submain(int argc, char * const argv[]); - -int main(int argc, char * const argv[]) { - char buffer[50000]; - bzero(buffer, 50000); - int r = submain(argc, argv); - printf("%s", buffer); - return r; -} diff --git a/dmidecodemodule.c b/dmidecodemodule.c index 8f3e251..75d4101 100644 --- a/dmidecodemodule.c +++ b/dmidecodemodule.c @@ -65,8 +65,9 @@ u8 *parse_opt_type(u8 *p, const char *arg) { static PyObject* dmidecode_get(PyObject *self, const char* section) { - //mtrace(); + if(self == NULL) return NULL; + //mtrace(); /* This is `embedding API', not applicable to this dmidecode module which is `Extending' Py_SetProgramName("dmidecode"); @@ -173,18 +174,18 @@ static PyObject* dmidecode_get(PyObject *self, const char* section) { return pydata; } -static PyObject* dmidecode_get_bios(PyObject *self, PyObject *args) { return dmidecode_get(self, "bios"); } -static PyObject* dmidecode_get_system(PyObject *self, PyObject *args) { return dmidecode_get(self, "system"); } +static PyObject* dmidecode_get_bios(PyObject *self, PyObject *args) { return dmidecode_get(self, "bios"); } +static PyObject* dmidecode_get_system(PyObject *self, PyObject *args) { return dmidecode_get(self, "system"); } static PyObject* dmidecode_get_baseboard(PyObject *self, PyObject *args) { return dmidecode_get(self, "baseboard"); } -static PyObject* dmidecode_get_chassis(PyObject *self, PyObject *args) { return dmidecode_get(self, "chassis"); } +static PyObject* dmidecode_get_chassis(PyObject *self, PyObject *args) { return dmidecode_get(self, "chassis"); } static PyObject* dmidecode_get_processor(PyObject *self, PyObject *args) { return dmidecode_get(self, "processor"); } -static PyObject* dmidecode_get_memory(PyObject *self, PyObject *args) { return dmidecode_get(self, "memory"); } -static PyObject* dmidecode_get_cache(PyObject *self, PyObject *args) { return dmidecode_get(self, "cache"); } +static PyObject* dmidecode_get_memory(PyObject *self, PyObject *args) { return dmidecode_get(self, "memory"); } +static PyObject* dmidecode_get_cache(PyObject *self, PyObject *args) { return dmidecode_get(self, "cache"); } static PyObject* dmidecode_get_connector(PyObject *self, PyObject *args) { return dmidecode_get(self, "connector"); } -static PyObject* dmidecode_get_slot(PyObject *self, PyObject *args) { return dmidecode_get(self, "slot"); } -static PyObject* dmidecode_get_type(PyObject *self, PyObject *args) { +static PyObject* dmidecode_get_slot(PyObject *self, PyObject *args) { return dmidecode_get(self, "slot"); } +static PyObject* dmidecode_get_type(PyObject *self, PyObject *args) { const char *s; - if(PyArg_ParseTuple(args, "s", &s)) + if(PyArg_ParseTuple(args, (char *)"s", &s)) return dmidecode_get(self, s); return Py_None; } @@ -193,10 +194,13 @@ static PyObject* dmidecode_dump(PyObject *self, PyObject *args) { return Py_Fals static PyObject* dmidecode_load(PyObject *self, PyObject *args) { return Py_False; } static PyObject* dmidecode_get_dev(PyObject *self, PyObject *null) { + if(self == NULL) return NULL; if(opt.dumpfile != NULL) return opt.dumpfile; else return PyString_FromString(opt.devmem); } + static PyObject* dmidecode_set_dev(PyObject *self, PyObject *arg) { + if(self == NULL) return NULL; if(PyString_Check(arg)) { if(opt.dumpfile) { Py_DECREF(opt.dumpfile); } opt.dumpfile = arg; @@ -211,26 +215,26 @@ static PyObject* dmidecode_set_dev(PyObject *self, PyObject *arg) { PyMethodDef DMIDataMethods[] = { - { "dump", dmidecode_dump, METH_NOARGS, "Dump dmidata to set file" }, - { "load", dmidecode_load, METH_NOARGS, "Load dmidata from set file" }, - { "get_dev", dmidecode_get_dev, METH_NOARGS, "Set an alternative memory device file" }, - { "set_dev", dmidecode_set_dev, METH_O, "Set an alternative memory device file" }, - - { "bios", dmidecode_get_bios, METH_VARARGS, "BIOS Data" }, - { "system", dmidecode_get_system, METH_VARARGS, "System Data" }, - { "baseboard", dmidecode_get_baseboard, METH_VARARGS, "Baseboard Data" }, - { "chassis", dmidecode_get_chassis, METH_VARARGS, "Chassis Data" }, - { "processor", dmidecode_get_processor, METH_VARARGS, "Processor Data" }, - { "memory", dmidecode_get_memory, METH_VARARGS, "Memory Data" }, - { "cache", dmidecode_get_cache, METH_VARARGS, "Cache Data" }, - { "connector", dmidecode_get_connector, METH_VARARGS, "Connector Data" }, - { "slot", dmidecode_get_slot, METH_VARARGS, "Slot Data" }, - { "type", dmidecode_get_type, METH_VARARGS, "By Type" }, + { (char *)"dump", dmidecode_dump, METH_NOARGS, (char *)"Dump dmidata to set file" }, + { (char *)"load", dmidecode_load, METH_NOARGS, (char *)"Load dmidata from set file" }, + { (char *)"get_dev", dmidecode_get_dev, METH_NOARGS, (char *)"Set an alternative memory device file" }, + { (char *)"set_dev", dmidecode_set_dev, METH_O, (char *)"Set an alternative memory device file" }, + + { (char *)"bios", dmidecode_get_bios, METH_VARARGS, (char *)"BIOS Data" }, + { (char *)"system", dmidecode_get_system, METH_VARARGS, (char *)"System Data" }, + { (char *)"baseboard", dmidecode_get_baseboard, METH_VARARGS, (char *)"Baseboard Data" }, + { (char *)"chassis", dmidecode_get_chassis, METH_VARARGS, (char *)"Chassis Data" }, + { (char *)"processor", dmidecode_get_processor, METH_VARARGS, (char *)"Processor Data" }, + { (char *)"memory", dmidecode_get_memory, METH_VARARGS, (char *)"Memory Data" }, + { (char *)"cache", dmidecode_get_cache, METH_VARARGS, (char *)"Cache Data" }, + { (char *)"connector", dmidecode_get_connector, METH_VARARGS, (char *)"Connector Data" }, + { (char *)"slot", dmidecode_get_slot, METH_VARARGS, (char *)"Slot Data" }, + { (char *)"type", dmidecode_get_type, METH_VARARGS, (char *)"By Type" }, { NULL, NULL, 0, NULL } }; PyMODINIT_FUNC initdmidecode(void) { init(); - (void) Py_InitModule("dmidecode", DMIDataMethods); + (void)Py_InitModule((char *)"dmidecode", DMIDataMethods); } diff --git a/dmidecodemodule.h b/dmidecodemodule.h index 1738d69..02131c6 100644 --- a/dmidecodemodule.h +++ b/dmidecodemodule.h @@ -53,3 +53,5 @@ static const struct type_keyword opt_type_keyword[] = { { "connector", opt_type_connector }, { "slot", opt_type_slot }, }; + +PyMODINIT_FUNC initdmidecode(void); diff --git a/dmihelper.h b/dmihelper.h index 290c234..63415fe 100644 --- a/dmihelper.h +++ b/dmihelper.h @@ -8,6 +8,7 @@ #include <stdio.h> #include <stdlib.h> #include <assert.h> + #include "types.h" #define MAXVAL 1024 diff --git a/dmiopt.c b/dmiopt.c deleted file mode 100644 index 4456d9f..0000000 --- a/dmiopt.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Command line handling of dmidecode - * This file is part of the dmidecode project. - * - * Copyright (C) 2005-2008 Jean Delvare <khali@linux-fr.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <stdio.h> -#include <strings.h> -#include <stdlib.h> -#include <getopt.h> - -#include "config.h" -#include "types.h" -#include "util.h" -#include "dmidecode.h" -#include "dmiopt.h" - - -/* Options are global */ -struct opt opt; - - -/* - * Handling of option --type - */ - -struct type_keyword -{ - const char *keyword; - const u8 *type; -}; - -static const u8 opt_type_bios[] = { 0, 13, 255 }; -static const u8 opt_type_system[] = { 1, 12, 15, 23, 32, 255 }; -static const u8 opt_type_baseboard[] = { 2, 10, 255 }; -static const u8 opt_type_chassis[] = { 3, 255 }; -static const u8 opt_type_processor[] = { 4, 255 }; -static const u8 opt_type_memory[] = { 5, 6, 16, 17, 255 }; -static const u8 opt_type_cache[] = { 7, 255 }; -static const u8 opt_type_connector[] = { 8, 255 }; -static const u8 opt_type_slot[] = { 9, 255 }; - -static const struct type_keyword opt_type_keyword[] = { - { "bios", opt_type_bios }, - { "system", opt_type_system }, - { "baseboard", opt_type_baseboard }, - { "chassis", opt_type_chassis }, - { "processor", opt_type_processor }, - { "memory", opt_type_memory }, - { "cache", opt_type_cache }, - { "connector", opt_type_connector }, - { "slot", opt_type_slot }, -}; - -static void print_opt_type_list(void) -{ - unsigned int i; - - fprintf(stderr, "Valid type keywords are:\n"); - for (i = 0; i < ARRAY_SIZE(opt_type_keyword); i++) - { - fprintf(stderr, " %s\n", opt_type_keyword[i].keyword); - } -} - -u8 *parse_opt_type(u8 *p, const char *arg) -{ - unsigned int i; - - /* Allocate memory on first call only */ - if (p == NULL) - { - p = (u8 *)calloc(256, sizeof(u8)); - if (p == NULL) - { - perror("calloc"); - return NULL; - } - } - - /* First try as a keyword */ - for (i = 0; i < ARRAY_SIZE(opt_type_keyword); i++) - { - if (!strcasecmp(arg, opt_type_keyword[i].keyword)) - { - int j = 0; - while (opt_type_keyword[i].type[j] != 255) - p[opt_type_keyword[i].type[j++]] = 1; - goto found; - } - } - - /* Else try as a number */ - while (*arg != '\0') - { - unsigned long val; - char *next; - - val = strtoul(arg, &next, 0); - if (next == arg) - { - fprintf(stderr, "Invalid type keyword: %s\n", arg); - print_opt_type_list(); - goto exit_free; - } - if (val > 0xff) - { - fprintf(stderr, "Invalid type number: %lu\n", val); - goto exit_free; - } - - p[val] = 1; - arg = next; - while (*arg == ',' || *arg == ' ') - arg++; - } - -found: - return p; - -exit_free: - free(p); - return NULL; -} - - -/* - * Handling of option --string - */ - -/* This lookup table could admittedly be reworked for improved performance. - Due to the low count of items in there at the moment, it did not seem - worth the additional code complexity though. */ -static const struct string_keyword opt_string_keyword[] = { - { "bios-vendor", 0, 0x04 }, - { "bios-version", 0, 0x05 }, - { "bios-release-date", 0, 0x08 }, - { "system-manufacturer", 1, 0x04 }, - { "system-product-name", 1, 0x05 }, - { "system-version", 1, 0x06 }, - { "system-serial-number", 1, 0x07 }, - { "system-uuid", 1, 0x08 }, /* dmi_system_uuid() */ - { "baseboard-manufacturer", 2, 0x04 }, - { "baseboard-product-name", 2, 0x05 }, - { "baseboard-version", 2, 0x06 }, - { "baseboard-serial-number", 2, 0x07 }, - { "baseboard-asset-tag", 2, 0x08 }, - { "chassis-manufacturer", 3, 0x04 }, - { "chassis-type", 3, 0x05 }, /* dmi_chassis_type() */ - { "chassis-version", 3, 0x06 }, - { "chassis-serial-number", 3, 0x07 }, - { "chassis-asset-tag", 3, 0x08 }, - { "processor-family", 4, 0x06 }, /* dmi_processor_family() */ - { "processor-manufacturer", 4, 0x07 }, - { "processor-version", 4, 0x10 }, - { "processor-frequency", 4, 0x16 }, /* dmi_processor_frequency() */ -}; - -static void print_opt_string_list(void) -{ - unsigned int i; - - fprintf(stderr, "Valid string keywords are:\n"); - for (i = 0; i < ARRAY_SIZE(opt_string_keyword); i++) - { - fprintf(stderr, " %s\n", opt_string_keyword[i].keyword); - } -} - -static int parse_opt_string(const char *arg) -{ - unsigned int i; - - if (opt.string) - { - fprintf(stderr, "Only one string can be specified\n"); - return -1; - } - - for (i = 0; i < ARRAY_SIZE(opt_string_keyword); i++) - { - if (!strcasecmp(arg, opt_string_keyword[i].keyword)) - { - opt.string = &opt_string_keyword[i]; - return 0; - } - } - - fprintf(stderr, "Invalid string keyword: %s\n", arg); - print_opt_string_list(); - return -1; -} - - -/* - * Command line options handling - */ - -/* Return -1 on error, 0 on success */ -int parse_command_line(int argc, char * const argv[]) -{ - int option; - const char *optstring = "d:hqs:t:uV"; - struct option longopts[] = { - { "dev-mem", required_argument, NULL, 'd' }, - { "help", no_argument, NULL, 'h' }, - { "quiet", no_argument, NULL, 'q' }, - { "string", required_argument, NULL, 's' }, - { "type", required_argument, NULL, 't' }, - { "dump", no_argument, NULL, 'u' }, - { "dump-bin", required_argument, NULL, 'B' }, - { "from-dump", required_argument, NULL, 'F' }, - { "version", no_argument, NULL, 'V' }, - { 0, 0, 0, 0 } - }; - - while ((option = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) - switch (option) - { - case 'B': - opt.flags |= FLAG_DUMP_BIN; - opt.dumpfile = optarg; - break; - case 'F': - opt.flags |= FLAG_FROM_DUMP; - opt.dumpfile = optarg; - break; - case 'd': - opt.devmem = optarg; - break; - case 'h': - opt.flags |= FLAG_HELP; - break; - case 'q': - opt.flags |= FLAG_QUIET; - break; - case 's': - if (parse_opt_string(optarg) < 0) - return -1; - opt.flags |= FLAG_QUIET; - break; - case 't': - opt.type = parse_opt_type(opt.type, optarg); - if (opt.type == NULL) - return -1; - break; - case 'u': - opt.flags |= FLAG_DUMP; - break; - case 'V': - opt.flags |= FLAG_VERSION; - break; - case '?': - switch (optopt) - { - case 's': - fprintf(stderr, "String keyword expected\n"); - print_opt_string_list(); - break; - case 't': - fprintf(stderr, "Type number or keyword expected\n"); - print_opt_type_list(); - break; - } - return -1; - } - - /* Check for mutually exclusive output format options */ - if ((opt.string != NULL) + (opt.type != NULL) - + !!(opt.flags & FLAG_DUMP) + !!(opt.flags & FLAG_DUMP_BIN) > 1) - { - fprintf(stderr, "Options --string, --type, --dump and --dump-bin are mutually exclusive\n"); - return -1; - } - if (opt.flags & (FLAG_DUMP | FLAG_DUMP_BIN)) - opt.flags &= ~FLAG_QUIET; - - if ((opt.flags & FLAG_FROM_DUMP) && (opt.flags & FLAG_DUMP_BIN)) - { - fprintf(stderr, "Options --from-dump and --dump-bin are mutually exclusive\n"); - return -1; - } - - return 0; -} - -void print_help(void) -{ - static const char *help = - "Usage: dmidecode [OPTIONS]\n" - "Options are:\n" - " -d, --dev-mem FILE Read memory from device FILE (default: " DEFAULT_MEM_DEV ")\n" - " -h, --help Display this help text and exit\n" - " -q, --quiet Less verbose output\n" - " -s, --string KEYWORD Only display the value of the given DMI string\n" - " -t, --type TYPE Only display the entries of given type\n" - " -u, --dump Do not decode the entries\n" - " --dump-bin FILE Dump the DMI data to a binary file\n" - " --from-dump FILE Read the DMI data from a binary file\n" - " -V, --version Display the version and exit\n"; - - printf("%s", help); -} diff --git a/dmiopt.h b/dmiopt.h deleted file mode 100644 index 63af792..0000000 --- a/dmiopt.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Command line handling of dmidecode - * This file is part of the dmidecode project. - * - * Copyright (C) 2005-2008 Jean Delvare <khali@linux-fr.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -struct string_keyword -{ - const char *keyword; - u8 type; - u8 offset; -}; - -struct opt -{ - const char *devmem; - unsigned int flags; - u8 *type; - const struct string_keyword *string; - char *dumpfile; -}; -extern struct opt opt; - -#define FLAG_VERSION (1 << 0) -#define FLAG_HELP (1 << 1) -#define FLAG_DUMP (1 << 2) -#define FLAG_QUIET (1 << 3) -#define FLAG_DUMP_BIN (1 << 4) -#define FLAG_FROM_DUMP (1 << 5) - -int parse_command_line(int argc, char * const argv[]); -void print_help(void); -u8 *parse_opt_type(u8 *p, const char *arg); diff --git a/ownership.c b/ownership.c deleted file mode 100644 index 29b9850..0000000 --- a/ownership.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Compaq Ownership Tag - * - * (C) 2003-2005 Jean Delvare <khali@linux-fr.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For the avoidance of doubt the "preferred form" of this code is one which - * is in an open unpatent encumbered format. Where cryptographic key signing - * forms part of the process of creating an executable the information - * including keys needed to generate an equivalently functional executable - * are deemed to be part of the source code. - * - * References: - * - Compaq "Technical Reference Guide for Compaq Deskpro 4000 and 6000" - * First Edition - * http://h18000.www1.hp.com/support/techpubs/technical_reference_guides/113a1097.html - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <getopt.h> - -#include "version.h" -#include "config.h" -#include "types.h" -#include "util.h" - -/* Options are global */ -struct opt -{ - const char* devmem; - unsigned int flags; -}; -static struct opt opt; - -#define FLAG_VERSION (1<<0) -#define FLAG_HELP (1<<1) - -static void ownership(u32 base, const char *pname, const char *devmem) -{ - u8 *buf; - int i; - - /* read the ownership tag */ - if((buf=mem_chunk(base, 0x51, devmem))==NULL) - { - perror(pname); - return; - } - - /* chop the trailing garbage */ - i=0x4f; - while(i>=0 && (buf[i]==0x20 || buf[i]==0x00)) - i--; - buf[i+1]='\0'; - - /* filter and print */ - if(i>=0) - { - for(; i>=0; i--) - { - if(buf[i]<32 || (buf[i]>=127 && buf[i]<160)) - buf[i]='?'; - } - printf("%s\n", (char *)buf); - } - - free(buf); -} - -static u32 decode(const u8 *p) -{ - int i; - - /* integrity checking (lack of checksum) */ - for(i=0; i<p[4]; i++) - { - if(p[5+i*10]!='$' || !(p[6+i*10]>='A' && p[6+i*10]<='Z') - || !(p[7+i*10]>='A' && p[7+i*10]<='Z') - || !(p[8+i*10]>='A' && p[8+i*10]<='Z')) - { - printf("\t Abnormal Entry! Please report. [%02x %02x %02x %02x]\n", - p[5+i*10], p[6+i*10], p[7+i*10], p[8+i*10]); - return 0; - } - } - - /* search for the right entry */ - for(i=0; i<p[4]; i++) - if(memcmp(p+5+i*10, "$ERB", 4)==0) - return DWORD(p+9+i*10); - - return 0; -} - -/* Return -1 on error, 0 on success */ -static int parse_command_line(int argc, char * const argv[]) -{ - int option; - const char *optstring = "d:hV"; - struct option longopts[]={ - { "dev-mem", required_argument, NULL, 'd' }, - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'V' }, - { 0, 0, 0, 0 } - }; - - while((option=getopt_long(argc, argv, optstring, longopts, NULL))!=-1) - switch(option) - { - case 'd': - opt.devmem=optarg; - break; - case 'h': - opt.flags|=FLAG_HELP; - break; - case 'V': - opt.flags|=FLAG_VERSION; - break; - case '?': - return -1; - } - - return 0; -} - -static void print_help(void) -{ - static const char *help= - "Usage: ownership [OPTIONS]\n" - "Options are:\n" - " -d, --dev-mem FILE Read memory from device FILE (default: " DEFAULT_MEM_DEV ")\n" - " -h, --help Display this help text and exit\n" - " -V, --version Display the version and exit\n"; - - printf("%s", help); -} - -int main(int argc, char * const argv[]) -{ - u8 *buf; - off_t fp; - int ok=0; - - if(sizeof(u8)!=1 || sizeof(u32)!=4) - { - fprintf(stderr, "%s: compiler incompatibility\n", argv[0]); - exit(255); - } - - /* Set default option values */ - opt.devmem=DEFAULT_MEM_DEV; - opt.flags=0; - - if(parse_command_line(argc, argv)<0) - exit(2); - - if(opt.flags & FLAG_HELP) - { - print_help(); - return 0; - } - - if(opt.flags & FLAG_VERSION) - { - printf("%s\n", VERSION); - return 0; - } - - if((buf=mem_chunk(0xE0000, 0x20000, opt.devmem))==NULL) - exit(1); - - for(fp=0; !ok && fp<=0x1FFF0; fp+=16) - { - u8 *p=buf+fp; - - if(memcmp((char *)p, "32OS", 4)==0) - { - off_t len=p[4]*10+5; - - if(fp+len-1<=0x1FFFF) - { - u32 base; - - if((base=decode(p))) - { - ok=1; - ownership(base, argv[0], opt.devmem); - } - } - } - } - - free(buf); - - return 0; -} diff --git a/vpddecode.c b/vpddecode.c deleted file mode 100644 index 4e00263..0000000 --- a/vpddecode.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * IBM Vital Product Data decoder - * - * (C) 2003-2005 Jean Delvare <khali@linux-fr.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For the avoidance of doubt the "preferred form" of this code is one which - * is in an open unpatent encumbered format. Where cryptographic key signing - * forms part of the process of creating an executable the information - * including keys needed to generate an equivalently functional executable - * are deemed to be part of the source code. - * - * References: - * - IBM "Using the BIOS Build ID to identify Thinkpad systems" - * Revision 2006-01-31 - * http://www-307.ibm.com/pc/support/site.wss/MIGR-45120.html - * - * Notes: - * - Main part of the code is taken directly from biosdecode, with an - * additional command line interface and a few experimental features. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "version.h" -#include "config.h" -#include "types.h" -#include "util.h" -#include "vpdopt.h" - -static void print_entry(const char *name, const u8 *p, size_t len) -{ - size_t i; - - if(name!=NULL) - printf("%s: ", name); - for(i=0; i<len; i++) - { - /* ASCII filtering */ - if(p[i]>=32 && p[i]<127) - printf("%c", p[i]); - else if(p[i]!=0) - printf("."); - } - printf("\n"); -} - -static void dump(const u8 *p, u8 len) -{ - int done, i, min; - - for(done=0; done<len; done+=16) - { - printf("%02X:", done); - min=(len-done<16)?len-done:16; - - /* As hexadecimal first */ - for(i=0; i<min; i++) - printf(" %02X", p[done+i]); - for(; i<16; i++) /* Complete line if needed */ - printf(" "); - printf(" "); - - /* And now as text, with ASCII filtering */ - for(i=0; i<min; i++) - printf("%c", (p[done+i]>=32 && p[done+i]<127)? - p[done+i]:'.'); - printf("\n"); - } -} - -static int decode(const u8 *p) -{ - if(p[5]<0x30) - return 0; - - /* XSeries have longer records, exact length seems to vary. */ - if(!(p[5]>=0x45 && checksum(p, p[5])) - /* Some Netvista seem to work with this. */ - && !(checksum(p, 0x30)) - /* The Thinkpad/Thinkcentre checksum does *not* include the first - 13 bytes. */ - && !(checksum(p+0x0D, 0x30-0x0D))) - { - /* A few systems have a bad checksum (xSeries 325, 330, 335 - and 345 with early BIOS) but the record is otherwise - valid. */ - if(!(opt.flags & FLAG_QUIET)) - printf("Bad checksum! Please report.\n"); - } - - if(opt.string!=NULL) - { - if(opt.string->offset+opt.string->len<p[5]) - print_entry(NULL, p+opt.string->offset, - opt.string->len); - return 1; - } - - print_entry("BIOS Build ID", p+0x0D, 9); - print_entry("Box Serial Number", p+0x16, 7); - print_entry("Motherboard Serial Number", p+0x1D, 11); - print_entry("Machine Type/Model", p+0x28, 7); - - if(p[5]<0x44) - return 1; - - print_entry("BIOS Release Date", p+0x30, 8); - print_entry("Default Flash Image File Name", p+0x38, 12); - - if(p[5]>=0x46 && p[0x44]!=0x00) - { - printf("%s: %u (Please report!)\n", "BIOS Revision", - p[0x44]); - } - - return 1; -} - -int main(int argc, char * const argv[]) -{ - u8 *buf; - int found=0; - unsigned int fp; - - if(sizeof(u8)!=1) - { - fprintf(stderr, "%s: compiler incompatibility\n", argv[0]); - exit(255); - } - - /* Set default option values */ - opt.devmem=DEFAULT_MEM_DEV; - opt.flags=0; - - if(parse_command_line(argc, argv)<0) - exit(2); - - if(opt.flags & FLAG_HELP) - { - print_help(); - return 0; - } - - if(opt.flags & FLAG_VERSION) - { - printf("%s\n", VERSION); - return 0; - } - - if(!(opt.flags & FLAG_QUIET)) - printf("# vpddecode %s\n", VERSION); - - if((buf=mem_chunk(0xF0000, 0x10000, opt.devmem))==NULL) - exit(1); - - for(fp=0; fp<=0xFFF0; fp+=4) - { - u8 *p=buf+fp; - - if(memcmp((char *)p, "\252\125VPD", 5)==0 - && fp+p[5]-1<=0xFFFF) - { - if(fp%16 && !(opt.flags & FLAG_QUIET)) - printf("Unaligned address (%#x), please report!\n", - 0xf0000+fp); - if(opt.flags & FLAG_DUMP) - { - dump(p, p[5]); - found++; - } - else - { - if(decode(p)) - found++; - } - } - } - - free(buf); - - if(!found && !(opt.flags && FLAG_QUIET)) - printf("# No VPD structure found, sorry.\n"); - - return 0; -} diff --git a/vpdopt.c b/vpdopt.c deleted file mode 100644 index 021ade2..0000000 --- a/vpdopt.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Command line handling of vpddecode - * This file is part of the dmidecode project. - * - * Copyright (C) 2005-2007 Jean Delvare <khali@linux-fr.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <stdio.h> -#include <strings.h> -#include <stdlib.h> -#include <getopt.h> - -#include "config.h" -#include "util.h" -#include "vpdopt.h" - - -/* Options are global */ -struct opt opt; - - -/* - * Handling of option --string - */ - -/* This lookup table could admittedly be reworked for improved performance. - Due to the low count of items in there at the moment, it did not seem - worth the additional code complexity though. */ -static const struct string_keyword opt_string_keyword[] = { - { "bios-build-id", 0x0D, 9 }, - { "box-serial-number", 0x16, 7 }, - { "motherboard-serial-number", 0x1D, 11 }, - { "machine-type-model", 0x28, 7 }, - { "bios-release-date", 0x30, 8 }, -}; - -static void print_opt_string_list(void) -{ - unsigned int i; - - fprintf(stderr, "Valid string keywords are:\n"); - for (i = 0; i < ARRAY_SIZE(opt_string_keyword); i++) - { - fprintf(stderr, " %s\n", opt_string_keyword[i].keyword); - } -} - -static int parse_opt_string(const char *arg) -{ - unsigned int i; - - if (opt.string) - { - fprintf(stderr, "Only one string can be specified\n"); - return -1; - } - - for (i = 0; i<ARRAY_SIZE(opt_string_keyword); i++) - { - if (!strcasecmp(arg, opt_string_keyword[i].keyword)) - { - opt.string = &opt_string_keyword[i]; - return 0; - } - } - - fprintf(stderr, "Invalid string keyword: %s\n", arg); - print_opt_string_list(); - return -1; -} - - -/* - * Command line options handling - */ - -/* Return -1 on error, 0 on success */ -int parse_command_line(int argc, char * const argv[]) -{ - int option; - const char *optstring = "d:hs:uV"; - struct option longopts[] = { - { "dev-mem", required_argument, NULL, 'd' }, - { "help", no_argument, NULL, 'h' }, - { "string", required_argument, NULL, 's' }, - { "dump", no_argument, NULL, 'u' }, - { "version", no_argument, NULL, 'V' }, - { 0, 0, 0, 0 } - }; - - while ((option = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) - switch (option) - { - case 'd': - opt.devmem = optarg; - break; - case 'h': - opt.flags |= FLAG_HELP; - break; - case 's': - if (parse_opt_string(optarg) < 0) - return -1; - opt.flags |= FLAG_QUIET; - break; - case 'u': - opt.flags |= FLAG_DUMP; - break; - case 'V': - opt.flags |= FLAG_VERSION; - break; - case '?': - switch (optopt) - { - case 's': - fprintf(stderr, "String keyword expected\n"); - print_opt_string_list(); - break; - } - return -1; - } - - if ((opt.flags & FLAG_DUMP) && opt.string != NULL) - { - fprintf(stderr, "Options --string and --dump are mutually exclusive\n"); - return -1; - } - - return 0; -} - -void print_help(void) -{ - static const char *help = - "Usage: vpddecode [OPTIONS]\n" - "Options are:\n" - " -d, --dev-mem FILE Read memory from device FILE (default: " DEFAULT_MEM_DEV ")\n" - " -h, --help Display this help text and exit\n" - " -s, --string KEYWORD Only display the value of the given VPD string\n" - " -u, --dump Do not decode the VPD records\n" - " -V, --version Display the version and exit\n"; - - printf("%s", help); -} diff --git a/vpdopt.h b/vpdopt.h deleted file mode 100644 index fceb552..0000000 --- a/vpdopt.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Command line handling of vpddecode - * This file is part of the dmidecode project. - * - * Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <sys/types.h> - -struct string_keyword -{ - const char *keyword; - off_t offset; - size_t len; -}; - -struct opt -{ - const char *devmem; - unsigned int flags; - const struct string_keyword *string; -}; -extern struct opt opt; - -#define FLAG_VERSION (1 << 0) -#define FLAG_HELP (1 << 1) -#define FLAG_DUMP (1 << 2) -#define FLAG_QUIET (1 << 3) - -int parse_command_line(int argc, char * const argv[]); -void print_help(void); |