summarylogtreecommitdiffstats
path: root/cpuinfo-from-devicetree.patch
blob: 0aeaaa8b3e2e71d3e5cfee6c19cd55edd1630546 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
diff -r c53985209d09 source/cpuinfo.c
--- a/source/cpuinfo.c	Sun Oct 30 22:41:09 2016 +0000
+++ b/source/cpuinfo.c	Wed Feb 22 17:15:44 2017 +0100
@@ -34,6 +34,8 @@
    char *rev;
    int found = 0;
    int len;
+   char *line;
+   size_t linelen = 128;
 
    if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
       return -1;
@@ -51,8 +53,70 @@
    }
    fclose(fp);
 
-   if (!found)
+   if (!found) {
+      // We may have data from the device-tree
+      if ((fp = fopen("/proc/device-tree/compatible", "r")) != NULL) {
+         line = calloc(linelen, sizeof(char));
+
+         while (getdelim(&line, &linelen, '\0', fp) != -1) {
+            // Look for the board model
+            if (strstr(line, "raspberrypi,model-a")) {
+               info->type = "Model A";
+               info->p1_revision = 2;
+               info->ram = "256M";
+            } else if (strstr(line, "raspberrypi,model-b")) {
+               info->type = "Model B";
+               info->p1_revision = 2;
+               info->ram = "256M";
+            } else if (strstr(line, "raspberrypi,model-a-plus")) {
+               info->type = "Model A+";
+               info->p1_revision = 3;
+               info->ram = "Unknown";
+            } else if (strstr(line, "raspberrypi,model-b-plus")) {
+               info->type = "Model B+";
+               info->p1_revision = 3;
+               info->ram = "512M";
+            } else if (strstr(line, "raspberrypi,2-model-b")) {
+               info->type = "Pi 2 Model B";
+               info->p1_revision = 3;
+               info->ram = "1G";
+            } else if (strstr(line, "raspberrypi,compute-module")) {
+               info->type = "Compute";
+               info->p1_revision = 0;
+               info->ram = "512M";
+            } else if (strstr(line, "raspberrypi,3-model-b")) {
+               info->type = "Pi 3 Model B";
+               info->p1_revision = 3;
+               info->ram = "1G";
+            } else if (strstr(line, "raspberrypi,model-zero")) {
+               info->type = "Zero";
+               info->p1_revision = 3;
+               info->ram = "512M";
+            } else if (strstr(line, "raspberrypi,model-b-rev2")) {
+               info->type = "Model B";
+               info->p1_revision = 2;
+               info->ram = "Unknown";
+            }
+           
+            // Look for CPU part 
+            if (strstr(line, "brcm,bcm2835")) {
+		         info->processor = "BCM2835";
+            } else if (strstr(line, "brcm,bcm2836")) {
+		         info->processor = "BCM2836";
+            } else if (strstr(line, "brcm,bcm2837")) {
+		         info->processor = "BCM2837";
+            }
+         }
+         free(line);
+
+         info->manufacturer = "Unknown";
+         fclose(fp);
+
+         return 0;
+      }
+
       return -1;
+   }
 
    if ((len = strlen(revision)) == 0)
       return -1;