Skip to content

Instantly share code, notes, and snippets.

@bookwar
Created July 16, 2017 21:40
Show Gist options
  • Save bookwar/1c78c22b18366d813a1e0202ca5305fa to your computer and use it in GitHub Desktop.
Save bookwar/1c78c22b18366d813a1e0202ca5305fa to your computer and use it in GitHub Desktop.
raspberry-pi cpuinfo

Libraries use cpuinfo to determine the raspbery pi version. But it doesn't work as Hardware and Revision are not set in Fedora

Fedora 26

# cat /proc/cpuinfo
...
processor	: 3
model name	: ARMv7 Processor rev 4 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

Hardware	: Generic DT based system
Revision	: 0000

From some Raspbian

processor       : 3
model name      : ARMv7 Processor rev 4 (v7l)
BogoMIPS        : 76.80
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

Hardware        : BCM2709
Revision        : a02082

From paspberry-gpio-python

https://sourceforge.net/p/raspberry-gpio-python/code/ci/default/tree/source/cpuinfo.c

   if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
      return -1;
   while(!feof(fp)) {
      fgets(buffer, sizeof(buffer), fp);
      sscanf(buffer, "Hardware	: %s", hardware);
      if (strcmp(hardware, "BCM2708") == 0 ||
          strcmp(hardware, "BCM2709") == 0 ||
          strcmp(hardware, "BCM2835") == 0 ||
          strcmp(hardware, "BCM2836") == 0 ||
          strcmp(hardware, "BCM2837") == 0 ) {
         found = 1;
      }
      sscanf(buffer, "Revision	: %s", revision);
   }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment