aboutsummaryrefslogtreecommitdiff
path: root/modules/devices.c
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2017-05-21 23:44:01 -0500
committerLeandro A. F. Pereira <leandro@hardinfo.org>2017-06-02 12:50:14 -0700
commita7de98bb61e5b42e91e22180b26d23eef6106991 (patch)
treec5b59f631a6659a5856db46abe9ca8de5dda1480 /modules/devices.c
parent6c4401dd00a2ed4cb2c6373f5e7906fa8cebc352 (diff)
Get board information for Raspberry Pis
get_motherboard() will now return something for Raspberry Pi boards. example: "Raspberry Pi 3 (Q1 2016) pcb-rev:1.2 soc:BCM2835 mem:1GB mfg-by:Sony" Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules/devices.c')
-rw-r--r--modules/devices.c103
1 files changed, 101 insertions, 2 deletions
diff --git a/modules/devices.c b/modules/devices.c
index 93d4958e..1377bfe8 100644
--- a/modules/devices.c
+++ b/modules/devices.c
@@ -195,12 +195,105 @@ gchar *get_memory_total(void)
return moreinfo_lookup ("DEV:Total Memory"); //hi_more_info(N_("Total Memory"));
}
+/* from: http://elinux.org/RPi_HardwareHistory */
+static struct {
+ char *value, *intro, *model, *pcb, *mem, *mfg;
+} rpi_boardinfo[] = {
+/* Value Introduction Model Name PCB rev. Memory Manufacturer *
+ * Raspberry Pi %s */
+ { "Beta", "Q1 2012", "B (Beta)", "?", "256MB", "(Beta board)" },
+ { "0002", "Q1 2012", "B", "1.0", "256MB", "" },
+ { "0003", "Q3 2012", "B (ECN0001)", "1.0", "256MB", "(Fuses mod and D14 removed)" },
+ { "0004", "Q3 2012", "B", "2.0", "256MB", "Sony" },
+ { "0005", "Q4 2012", "B", "2.0", "256MB", "Qisda" },
+ { "0006", "Q4 2012", "B", "2.0", "256MB", "Egoman" },
+ { "0007", "Q1 2013", "A", "2.0", "256MB", "Egoman" },
+ { "0008", "Q1 2013", "A", "2.0", "256MB", "Sony" },
+ { "0009", "Q1 2013", "A", "2.0", "256MB", "Qisda" },
+ { "000d", "Q4 2012", "B", "2.0", "512MB", "Egoman" },
+ { "000e", "Q4 2012", "B", "2.0", "512MB", "Sony" },
+ { "000f", "Q4 2012", "B", "2.0", "512MB", "Qisda" },
+ { "0010", "Q3 2014", "B+", "1.0", "512MB", "Sony" },
+ { "0011", "Q2 2014", "Compute Module 1", "1.0", "512MB", "Sony" },
+ { "0012", "Q4 2014", "A+", "1.1", "256MB", "Sony" },
+ { "0013", "Q1 2015", "B+", "1.2", "512MB", "?" },
+ { "0014", "Q2 2014", "Compute Module 1", "1.0", "512MB", "Embest" },
+ { "0015", "?", "A+", "1.1", "256MB/512MB", "Embest" },
+ { "a01040", "Unknown", "2 Model B", "1.0", "1GB", "Sony" },
+ { "a01041", "Q1 2015", "2 Model B", "1.1", "1GB", "Sony" },
+ { "a21041", "Q1 2015", "2 Model B", "1.1", "1GB", "Embest" },
+ { "a22042", "Q3 2016", "2 Model B (with BCM2837)", "1.2", "1GB", "Embest" },
+ { "900021", "Q3 2016", "A+", "1.1", "512MB", "Sony" },
+ { "900032", "Q2 2016?", "B+", "1.2", "512MB", "Sony" },
+ { "900092", "Q4 2015", "Zero", "1.2", "512MB", "Sony" },
+ { "900093", "Q2 2016", "Zero", "1.3", "512MB", "Sony" },
+ { "920093", "Q4 2016?", "Zero", "1.3", "512MB", "Embest" },
+ { "9000c1", "Q1 2017", "Zero W", "1.1", "512MB", "Sony" },
+ { "a02082", "Q1 2016", "3 Model B", "1.2", "1GB", "Sony" },
+ { "a020a0", "Q1 2017", "Compute Module 3 (and CM3 Lite)", "1.0", "1GB", "Sony" },
+ { "a22082", "Q1 2016", "3 Model B", "1.2", "1GB", "Embest" },
+ { "a32082", "Q4 2016", "3 Model B", "1.2", "1GB", "Sony Japan" },
+ { NULL, NULL, NULL, NULL, NULL, NULL }
+};
+
+gchar *rpi_get_boardname(void) {
+ int i = 0, c = 0;
+ gchar *ret = NULL;
+ gchar *soc = NULL;
+ gchar *revision = NULL;
+ int overvolt = 0;
+ FILE *cpuinfo;
+ gchar buffer[128];
+
+ cpuinfo = fopen("/proc/cpuinfo", "r");
+ if (!cpuinfo)
+ return NULL;
+ while (fgets(buffer, 128, cpuinfo)) {
+ gchar **tmp = g_strsplit(buffer, ":", 2);
+ tmp[0] = g_strstrip(tmp[0]);
+ tmp[1] = g_strstrip(tmp[1]);
+ get_str("Revision", revision);
+ get_str("Hardware", soc);
+ }
+ fclose(cpuinfo);
+
+ if (revision == NULL || soc == NULL) {
+ g_free(soc);
+ g_free(revision);
+ return NULL;
+ }
+
+ if (g_str_has_prefix(revision, "1000"))
+ overvolt = 1;
+
+ while (rpi_boardinfo[i].value != NULL) {
+ if (overvolt)
+ /* +4 to ignore the 1000 prefix */
+ c = g_strcmp0(revision+4, rpi_boardinfo[i].value);
+ else
+ c = g_strcmp0(revision, rpi_boardinfo[i].value);
+
+ if (c == 0) {
+ ret = g_strdup_printf("Raspberry Pi %s (%s) pcb-rev:%s soc:%s mem:%s mfg-by:%s%s",
+ rpi_boardinfo[i].model, rpi_boardinfo[i].intro,
+ rpi_boardinfo[i].pcb, soc,
+ rpi_boardinfo[i].mem, rpi_boardinfo[i].mfg,
+ (overvolt) ? " (over-volted)" : "" );
+ break;
+ }
+ i++;
+ }
+ g_free(soc);
+ g_free(revision);
+ return ret;
+}
+
gchar *get_motherboard(void)
{
char *board_name, *board_vendor;
#if defined(ARCH_x86) || defined(ARCH_x86_64)
scan_dmi(FALSE);
-#endif
+
board_name = moreinfo_lookup("DEV:DMI:Board:Name");
board_vendor = moreinfo_lookup("DEV:DMI:Board:Vendor");
@@ -210,7 +303,13 @@ gchar *get_motherboard(void)
return g_strconcat(board_name, _(" (vendor unknown)"), NULL);
else if (board_vendor && *board_vendor)
return g_strconcat(board_vendor, _(" (model unknown)"), NULL);
-
+#else
+ /* maybe it is an rpi */
+ board_name = rpi_get_boardname();
+ if (board_name != NULL)
+ return board_name;
+#endif
+
return g_strdup(_("Unknown"));
}