summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjamesbond <jamesbond>2014-07-28 17:01:25 +0000
committerLeandro Pereira <leandro@hardinfo.org>2015-10-25 15:49:33 -0200
commit6dd14fed6db519a2feb77a5b2b6e73ff03c4d043 (patch)
treea6784731925626be94d6ae0da328c30a8f0c4b53
parentda77fa093e35ca15d3b405c41b30f3cbbbe66c26 (diff)
revert commit [d5afcb6851]; fix the real cause of missing RAM display (use moreinfo_lookup rather than hi_more_info); fix usb display crashing (util.c now looks for lsusb in /usr/sbin first); fix glibc version not showing (glibc located in /lib64/libc.so.6); initial support for DDR3 spd-decoding (incomplete, the manufacturer is not shown yet).
-rw-r--r--hardinfo/util.c8
-rw-r--r--modules/computer.c2
-rw-r--r--modules/computer/os.c22
-rw-r--r--modules/devices.c6
-rw-r--r--modules/devices/spd-decode.c148
-rw-r--r--modules/devices/usb.c6
-rw-r--r--modules/network.c2
7 files changed, 167 insertions, 27 deletions
diff --git a/hardinfo/util.c b/hardinfo/util.c
index e94d215a..e9b2f930 100644
--- a/hardinfo/util.c
+++ b/hardinfo/util.c
@@ -54,10 +54,10 @@ gchar *find_program(gchar *program_name)
int i;
char *temp;
static GHashTable *cache = NULL;
- const char *path[] = { "/bin", "/sbin",
- "/usr/bin", "/usr/sbin",
- "/usr/local/bin", "/usr/local/sbin",
- NULL };
+ const char *path[] = { "/usr/local/bin", "/usr/local/sbin",
+ "/usr/bin", "/usr/sbin",
+ "/bin", "/sbin",
+ NULL };
/* we don't need to call stat() every time: cache the results */
if (!cache) {
diff --git a/modules/computer.c b/modules/computer.c
index 056af6a4..16c68217 100644
--- a/modules/computer.c
+++ b/modules/computer.c
@@ -84,7 +84,7 @@ static ModuleEntry entries[] = {
gchar *module_list = NULL;
Computer *computer = NULL;
-static gchar *hi_more_info(gchar * entry)
+gchar *hi_more_info(gchar * entry)
{
gchar *info = moreinfo_lookup_with_prefix("COMP", entry);
diff --git a/modules/computer/os.c b/modules/computer/os.c
index 39d0e020..41f8cb3a 100644
--- a/modules/computer/os.c
+++ b/modules/computer/os.c
@@ -26,14 +26,22 @@ get_libc_version(void)
{
FILE *libc;
gchar buf[256], *tmp, *p;
+ char *libc_paths[] = {
+ "/lib/ld-uClibc.so.0", "/lib64/ld-uClibc.so.0",
+ "/lib/libc.so.6", "/lib64/libc.so.6"
+ };
+ int i;
+
+ for (i=0; i < 4; i++) {
+ if (g_file_test(libc_paths[i], G_FILE_TEST_EXISTS)) break;
+ }
+ switch (i) {
+ case 0: case 1: return g_strdup("uClibc Library");
+ case 2: case 3: break; // gnu libc, continue processing
+ default: goto err;
+ }
- if (g_file_test("/lib/ld-uClibc.so.0", G_FILE_TEST_EXISTS)) {
- return g_strdup("uClibc Library");
- } else if (!g_file_test("/lib/libc.so.6", G_FILE_TEST_EXISTS)) {
- goto err;
- }
-
- libc = popen("/lib/libc.so.6", "r");
+ libc = popen(libc_paths[i], "r");
if (!libc) goto err;
(void)fgets(buf, 256, libc);
diff --git a/modules/devices.c b/modules/devices.c
index a749aeaa..60eed920 100644
--- a/modules/devices.c
+++ b/modules/devices.c
@@ -68,7 +68,7 @@ void scan_spd(gboolean reload);
#endif
void scan_device_resources(gboolean reload);
-static gchar *hi_more_info(gchar *entry);
+gchar *hi_more_info(gchar *entry);
static ModuleEntry entries[] = {
{N_("Processor"), "processor.png", callback_processors, scan_processors, MODULE_FLAG_NONE},
@@ -175,7 +175,7 @@ gchar *get_pci_device_description(gchar *pci_id)
gchar *get_memory_total(void)
{
scan_memory(FALSE);
- return hi_more_info(N_("Total Memory"));
+ return moreinfo_lookup ("DEV:Total Memory"); //hi_more_info(N_("Total Memory"));
}
gchar *get_motherboard(void)
@@ -215,7 +215,7 @@ ShellModuleMethod *hi_exported_methods(void)
return m;
}
-static gchar *hi_more_info(gchar * entry)
+gchar *hi_more_info(gchar * entry)
{
gchar *info = moreinfo_lookup_with_prefix("DEV", entry);
diff --git a/modules/devices/spd-decode.c b/modules/devices/spd-decode.c
index d559555f..a8db52d1 100644
--- a/modules/devices/spd-decode.c
+++ b/modules/devices/spd-decode.c
@@ -42,6 +42,7 @@ typedef enum {
DDR_SGRAM,
DDR_SDRAM,
DDR2_SDRAM,
+ DDR3_SDRAM
} RamType;
char *spd_info = NULL;
@@ -57,7 +58,8 @@ static const char *ram_types[] = {
"Multiplexed ROM",
"DDR SGRAM",
"DDR SDRAM",
- "DDR2 SDRAM"
+ "DDR2 SDRAM",
+ "DDR3 SDRAM"
};
static const char *vendors1[] = { "AMD", "AMI", "Fairchild", "Fujitsu",
@@ -1138,6 +1140,125 @@ static gchar *decode_ddr2_sdram(unsigned char *bytes, int *size)
}
+
+static void decode_ddr3_module_speed(unsigned char *bytes,
+ float *ddr_clock, int *pc3_speed)
+{
+ float ctime;
+ float ddrclk;
+ int tbits, pcclk;
+ float mtb=0.125;
+
+ if (bytes[10]==1 && bytes[11]==8) mtb=0.125;
+ if (bytes[10]==1 && bytes[11]==15) mtb=0.125;
+ ctime = mtb * bytes[12];
+
+ ddrclk = 2 * (1000 / ctime);
+
+ tbits=64;
+ switch (bytes[8]) {
+ case 1: tbits=16;
+ case 4: tbits=32;
+ case 3: case 0xb: tbits=64;
+ }
+
+ pcclk = ddrclk * tbits / 8;
+ pcclk -= pcclk % 100;
+
+ if (ddr_clock) {
+ *ddr_clock = (int) ddrclk;
+ }
+ if (pc3_speed) {
+ *pc3_speed = pcclk;
+ }
+}
+
+static void decode_ddr3_module_size(unsigned char *bytes, int *size)
+{
+ *size = 512 << bytes[4];
+}
+
+static void decode_ddr3_module_timings(unsigned char *bytes, float *trcd,
+ float *trp, float *tras, float *tcl)
+{
+ float ctime;
+ float highest_cas = 0;
+ int i;
+ float mtb=0.125;
+
+ if (bytes[10]==1 && bytes[11]==8) mtb=0.125;
+ if (bytes[10]==1 && bytes[11]==15) mtb=0.125;
+ ctime = mtb * bytes[12];
+
+ switch (bytes[14]) {
+ case 6: highest_cas = 5;
+ case 4: highest_cas = 6;
+ case 0xc: highest_cas = 7;
+ case 0x1e: highest_cas = 8;
+ }
+ if (trcd) {
+ *trcd = bytes[18] * mtb;
+ }
+
+ if (trp) {
+ *trp = bytes[20] * mtb;
+ }
+
+ if (tras) {
+ *tras = (bytes[22]+bytes[21] & 0xf)*mtb;
+ }
+
+ if (tcl) {
+ *tcl = highest_cas;
+ }
+}
+
+
+static gchar *decode_ddr3_sdram(unsigned char *bytes, int *size)
+{
+ float ddr_clock;
+ float trcd, trp, tras, tcl;
+ int pc3_speed;
+
+ decode_ddr3_module_speed(bytes, &ddr_clock, &pc3_speed);
+ decode_ddr3_module_size(bytes, size);
+ decode_ddr3_module_timings(bytes, &trcd, &trp, &tras, &tcl);
+
+ return g_strdup_printf("[Module Information]\n"
+ "Module type=DDR3 %.2f MHz (PC3-%d)\n"
+ "SPD revision=%d.%d\n"
+ "[Timings]\n"
+ "tCL=%.2f\n"
+ "tRCD=%.3fns\n"
+ "tRP=%.3fns\n"
+ "tRAS=%.3fns\n",
+ ddr_clock, pc3_speed,
+ bytes[1] >> 4, bytes[1] & 0xf,
+ tcl, trcd, trp, tras);
+}
+
+static void decode_ddr3_part_number(unsigned char *bytes,
+ char *part_number)
+{
+ int i;
+ if (part_number) {
+ for (i=128; i<=145; i++)
+ *part_number++ = bytes[i];
+ *part_number = '\0';
+ }
+}
+
+static void decode_ddr3_manufacturer(unsigned char *bytes,
+ char **manufacturer)
+{
+ char *out="Unknown";
+
+ end:
+ if (manufacturer) {
+ *manufacturer = out;
+ }
+}
+
static void decode_module_manufacturer(unsigned char *bytes,
char **manufacturer)
{
@@ -1179,7 +1300,7 @@ static void decode_module_part_number(unsigned char *bytes,
char *part_number)
{
if (part_number) {
- bytes += 8;
+ bytes += 8+64;
while (*bytes++ && *bytes >= 32 && *bytes < 127) {
*part_number++ = *bytes;
@@ -1215,6 +1336,8 @@ static int decode_ram_type(unsigned char *bytes)
return DDR_SDRAM;
case 8:
return DDR2_SDRAM;
+ case 11:
+ return DDR3_SDRAM;
}
}
@@ -1267,33 +1390,42 @@ static gchar *decode_dimms(GSList *dimm_list, gboolean use_sysfs)
gchar *detailed_info;
gchar *moreinfo_key;
gchar part_number[32];
- unsigned char bytes[64];
+ unsigned char bytes[256];
int module_size;
RamType ram_type;
shell_status_pulse();
- read_spd(spd_path, 0, 64, use_sysfs, bytes);
+ read_spd(spd_path, 0, 256, use_sysfs, bytes);
ram_type = decode_ram_type(bytes);
switch (ram_type) {
case DDR2_SDRAM:
- detailed_info = decode_ddr2_sdram(bytes, &module_size);
+ detailed_info = decode_ddr2_sdram(bytes, &module_size);
+ decode_module_part_number(bytes, part_number);
+ decode_module_manufacturer(bytes+64, &manufacturer);
+ break;
+ case DDR3_SDRAM:
+ detailed_info = decode_ddr3_sdram(bytes, &module_size);
+ decode_ddr3_part_number(bytes, part_number);
+ decode_ddr3_manufacturer(bytes, &manufacturer);
break;
case DDR_SDRAM:
detailed_info = decode_ddr_sdram(bytes, &module_size);
+ decode_module_part_number(bytes, part_number);
+ decode_module_manufacturer(bytes+64, &manufacturer);
break;
case SDR_SDRAM:
detailed_info = decode_sdr_sdram(bytes, &module_size);
+ decode_module_part_number(bytes, part_number);
+ decode_module_manufacturer(bytes+64, &manufacturer);
break;
default:
DEBUG("Unsupported EEPROM type: %s\n", ram_types[ram_type]);
continue;
}
- read_spd(spd_path, 64, 64, use_sysfs, bytes);
- decode_module_manufacturer(bytes, &manufacturer);
- decode_module_part_number(bytes, part_number);
+
gchar *key = g_strdup_printf("MEM%d", count);
moreinfo_add_with_prefix("DEV", key, g_strdup(detailed_info));
diff --git a/modules/devices/usb.c b/modules/devices/usb.c
index b8d9e305..3452932a 100644
--- a/modules/devices/usb.c
+++ b/modules/devices/usb.c
@@ -244,7 +244,7 @@ gboolean __scan_usb_procfs(void)
return n > 0;
}
-void __scan_usb_lsusb_add_device(char *buffer, FILE *lsusb, int usb_device_number)
+void __scan_usb_lsusb_add_device(char *buffer, int bufsize, FILE *lsusb, int usb_device_number)
{
gint bus, device, vendor_id, product_id;
gchar *version = NULL, *product = NULL, *vendor = NULL, *dev_class = NULL, *int_class = NULL;
@@ -255,7 +255,7 @@ void __scan_usb_lsusb_add_device(char *buffer, FILE *lsusb, int usb_device_numbe
sscanf(buffer, "Bus %d Device %d: ID %x:%x",
&bus, &device, &vendor_id, &product_id);
- for (position = ftell(lsusb); fgets(buffer, 512, lsusb); position = ftell(lsusb)) {
+ for (fgets(buffer, bufsize, lsusb); position = ftell(lsusb); fgets(buffer, bufsize, lsusb)) {
g_strstrip(buffer);
if (g_str_has_prefix(buffer, "idVendor")) {
@@ -371,7 +371,7 @@ gboolean __scan_usb_lsusb(void)
while (fgets(buffer, sizeof(buffer), temp_lsusb)) {
if (g_str_has_prefix(buffer, "Bus ")) {
- __scan_usb_lsusb_add_device(buffer, temp_lsusb, ++usb_device_number);
+ __scan_usb_lsusb_add_device(buffer, sizeof(buffer), temp_lsusb, ++usb_device_number);
}
}
diff --git a/modules/network.c b/modules/network.c
index c9f389f5..18f8ba65 100644
--- a/modules/network.c
+++ b/modules/network.c
@@ -379,7 +379,7 @@ gchar *callback_statistics()
__statistics);
}
-static gchar *hi_more_info(gchar * entry)
+gchar *hi_more_info(gchar * entry)
{
gchar *info = moreinfo_lookup_with_prefix("NET", entry);