Automatic Raspberry Pi board revision detection: model A, B1 and B2

When the raspberry Pi model A was announced a few days ago, I ordered one straight away. With three different models of raspberry Pi now available (or four, if you count the red Chinese variant), working out the capabilities of the board is becoming increasingly important. It’s vital for anyone involved in making hardware or software for other people to use, and it’s even pretty important for personal projects – you never know when you might want to use your hardware and software with a different board.

From my experimentation, here are the revision number values, and some useful things you can deduce from them:

Rev. No. Model Capabilities
0x2 B1 Original Model B, 256MB RAM, Ethernet, two USB sockets, five LEDs, (P2) JTAG pins, no mounting holes, Pin3=GPIO0, Pin5=GPIO1, Pin13=GPIO21, I2C-0
0x3 B1+ Original Model B with no polyfuses, 256MB RAM, Ethernet, two USB sockets, five LEDs, no mounting holes, Pin3=GPIO0, Pin5=GPIO1, Pin13=GPIO21, I2C-0
0x4 B2 Model B, 256MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
0x5 B2 Model B, 256MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
0x6 B2 Model B, 256MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
0x7 A Model A, 256MB RAM, no Ethernet, one USB socket, two LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, I2C-1, 8 extra IO pads (P5)
0x8 A Model A, 256MB RAM, no Ethernet, one USB socket, two LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, I2C-1, 8 extra IO pads (P5)
0x9 A Model A, 256MB RAM, no Ethernet, one USB socket, two LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, I2C-1, 8 extra IO pads (P5)
0xd B2 Rev2 Model B, 512MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
0xe B2 Rev2 Model B, 512MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
0xf B2 Rev2 Model B, 512MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)

Update: The above table has been extended based on Dom’s answer on the Raspberry Pi board

Apparently codes 0x4, 0x5, and 0x6 are allocated to B2 boards with 256MB RAM, although I have never seen one “in the wild”. If you have a board which responds with one of these numbers, or indeed anything else not in my table, please let me know!

Personally I have a B1 (0x2), a B2 (0xe) and an A (0x8). Now that I know how many there are, it kind of makes me want to collect them all ;)

Model B1, Model B2, Model A

Luckily the Raspberry Pi firmware provides ways to query the system about its revision number.

Here’s a few ways to find the revision number of the board your software is running on:

If you are running on Raspbian, check /proc/cmdline:

Language code
bash
cat /proc/cmdline | awk -v RS=" " -F= '/boardrev/ { print $2 }'
python
import re

def getrevision():
  revision = "unknown"
  with open('/proc/cmdline', 'r') as f:
    line = f.readline()
    m = re.search('bcm2708.boardrev=(0x[0123456789abcdef]*) ', line)
    revision = m.group(1)
  return revision

print getrevision()
ruby
def getrevision
  line = File.open("/proc/cmdline").first
  m = line.match /bcm2708.boardrev=(0x[0123456789abcdef]*) /
  return m[1]
end

puts getrevision
perl
open my $file, '<', "/proc/cmdline";
my $firstline = <$file>;
close $file;
$firstline =~ /bcm2708.boardrev=(0x[0123456789abcdef]*) /;
print "$1\n";
lua
io.input("/proc/cmdline")
s = io.read("*a")
print(s:match("bcm2708.boardrev=(0x%x*) "))
io.close()
C
#include 

char buf[1024];

void shift(char* window, int len) {
  int i;
  for (i = 1; i < len; ++i) {
    window[i-1] = window[i];
  }
  window[len-1] = 0;
}

void boardrev(char* dest) {
  FILE* f;
  int n = 0;
  int i;

  char window[5];
  int wi = 0;
  
  if (f= fopen("/proc/cmdline", "r")) {
    n = fread(buf, 1, 1023, f);
    fclose(f);
  }
  
  for (i = 0; i < n; ++i) {
    char c = buf[i];
    if (strcmp(window, "rev=") == 0) {
      while (buf[i] != ' ' && buf[i] != 0) {
        *dest++ = buf[i++];
      }
      *dest++ = 0;
      return;
    }
    if (wi < 4) {
      window[wi++] = c;
      window[wi] = 0;
    } else {
      shift(window, 4);
      window[3] = c;
    }
  }
}

void main() {
  char rev[10];
  boardrev(rev);
  printf("%s\n", rev);
}

If your program is running on the "bare metal" of the Raspberry Pi without an operating system to do this stuff for you, please see my previous article about reading Raspberry Pi revision numbers

30 Comments

  1. Pingback: Automatic #RaspberryPi board revision detection | Raspberry PiPod

  2. Pingback: Guide to #RaspberryPi revisions / @Raspberry_Pi | Raspberry PiPod

  3. Hi Frank, I’ve got a 0x4 board if you’re interested in any information from it. It was purchased as soon as the Sony manufacture announcement was made. I believe it was the first board to get the mounting holes, to be made in England, to be polyfuse free and to support powering the board by backfeeding the usb.

    Thanks for the code snippets above, I could do with updating some of my modules to automatically detect i2c buses.

    I’ve included a cpuinfo output below …

    pi@pitop ~ $ cat /proc/cpuinfo
    Processor : ARMv6-compatible processor rev 7 (v6l)
    BogoMIPS : 697.95
    Features : swp half thumb fastmult vfp edsp java tls
    CPU implementer : 0x41
    CPU architecture: 7
    CPU variant : 0x0
    CPU part : 0xb76
    CPU revision : 7

    Hardware : BCM2708
    Revision : 0004
    Serial : 00000000422e4101

    • Thanks for getting in touch. Presumably your board has only 256MB RAM, but is otherwise identical to the newer (0xd-0xf) B2 boards?

      I find all the discussion about powering the boards by back-feeding the USB to be a bit odd. I often power all my boards, including the 0x2 B1 board, from a USB-to-serial converter plugged into the UART pins on the GPIO header. It’s a great way to get a nice neat single-cable system, provides almost all the features of an ssh connection when used with Linux, and is easy to communicate with from bare metal software. In fact, it’s the only way I have been able to talk to my model A so far!

      • Yes, it was just before the upgrade to 512mb, but otherwise it looks to be identical.

        I’ve been powering them over the GPIO header in a few of my recent projects, but the usb backfeed can be quite handy too. I wrote up a tutorial for making up a Raspberry Pi Laptop using the Motorola Atrix Lapdock, and by backfeeding the Pi with usb power you can do the whole thing solder free.

        I’ve just been using a rather cheap StarTech ethernet adaptor on my Model A for now, and ssh’ing into it. I just wanted the ability to run it from something like a solar panel for longer term datalogging.

  4. Pingback: Automatic Raspberry Pi board revision detection: model A, B1 and B2 #piday #raspberrypi @Raspberry_Pi « adafruit industries blog

  5. Pingback: My post about board revisions seems to have been quite popular | Raspberry Alpha Omega

  6. Pingback: A pair of new goodies | Raspberry Alpha Omega

    • Hey Dave
      Do you really have a Raspberry Pi Alpha board? I’m starting a collection for my oldest son and looking for an alpha version. Would you be willing to part with it and if so what would be the cost. If I only had money when they were auctioning off the beta boards.

  7. Pingback: MAKE | Which Pi do I have?

  8. Pingback: Which Pi do I have? - IT Clips

  9. Hi Frank,
    Thanks for your work in getting all this information into one place. Have you thought about adding P6 data? I am also writing a shell script and during a cut and paste I noticed that your Model B data has 12C instead of I2C.
    Here’s a slightly shorter shell script:
    awk -v RS=” ” -F= ‘/boardrev/ { print $2 }’ /proc/cmdline

    regards

  10. Pingback: Elinizdeki Raspberry Pi Hangi Model Öğrenin | Raspberry Pi (RPi) Serüvenim

  11. …alternatively:
    cat /sys/module/bcm2708/parameters/boardrev

    which displays the result in decimal rather than hexadecimal. To print it in hexadecimal (as seen in /proc/cpuinfo and /proc/cmdline) you can use:
    printf “0x%X\n” `cat /sys/module/bcm2708/parameters/boardrev`

    I guess your big table now needs to be updated for the Model B+ :-)

  12. So, it appears I have an oddball board. The physical layout suggests it is an 0x3. It has no fuses, the P2 JTAG header and no mounting holes. But it has I2C-1. Running cat /proc/cmdline | awk -v RS=” ” -F= ‘/boardrev/ { print $2 }’ returns 0x0.

  13. cat /proc/cpuinfo
    processor : 0
    model name : ARMv6-compatible processor rev 7 (v6l)
    BogoMIPS : 2.00
    Features : half thumb fastmult vfp edsp java tls
    CPU implementer : 0x41
    CPU architecture: 7
    CPU variant : 0x0
    CPU part : 0xb76
    CPU revision : 7

    Hardware : BCM2708
    Revision : 0010
    Serial : 000000000a81b880

    My rev shows 0x10

  14. Pingback: Raspberry Pi Modelleri | diyot.net

  15. Slightly Improved Perl Script that has the table built in :-)

    #!/usr/bin/perl
    ##
    ## DETECT Raspberry Pi Model and Display its info summary
    ##
    open my $file, ‘<', "/proc/cmdline"; my $firstline = ; close $file;
    $firstline =~ /bcm2708.boardrev=(0x[0123456789abcdef]*) /; $model = hex($1);
    print “\nRaspberry Pi Model Information Tool\n”;
    print “===================================\n\n”;
    print “Detected RPI Hardware Model #: $1 ($model)\n\n”; $i=0;
    print “RevNo Model Capabilities\n”;
    print “===== ===== ============\n\n”;
    while ($line = ){ $i++; if ($i eq $model){ print $line;} }
    print “\n\n”;
    __DATA__
    RevNo Model Capabilities
    0x2 B1 Original Model B, 256MB RAM, Ethernet, two USB sockets, five LEDs, (P2) JTAG pins, no mounting holes, Pin3=GPIO0, Pin5=GPIO1, Pin13=GPIO21, I2C-0
    0x3 B1+ Original Model B with no polyfuses, 256MB RAM, Ethernet, two USB sockets, five LEDs, no mounting holes, Pin3=GPIO0, Pin5=GPIO1, Pin13=GPIO21, I2C-0
    0x4 B2 Model B, 256MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
    0x5 B2 Model B, 256MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
    0x6 B2 Model B, 256MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
    0x7 A Model A, 256MB RAM, no Ethernet, one USB socket, two LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, I2C-1, 8 extra IO pads (P5)
    0x8 A Model A, 256MB RAM, no Ethernet, one USB socket, two LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, I2C-1, 8 extra IO pads (P5)
    0x9 A Model A, 256MB RAM, no Ethernet, one USB socket, two LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, I2C-1, 8 extra IO pads (P5)
    0xa – unknown
    0xb – unknown
    0xc – unknown
    0xd B2 Rev2 Model B, 512MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
    0xe B2 Rev2 Model B, 512MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
    0xf B2 Rev2 Model B, 512MB RAM, Ethernet, two USB sockets, five LEDs, mounting holes, Pin3=GPIO1, Pin5=GPIO2, Pin13=GPIO27, 12C-1, 8 extra IO pads (P5)
    ##EOF##

  16. Just in case the “paste” of the perl script didn’t work, email me and I will email you back the perl script file so that it can be properly posted. (I noticed that wordpress munged some stuff in the scripted). :-)

Leave a Reply

Your email address will not be published. Required fields are marked *