Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get the Pi model
#!/bin/sh
# https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
cpuinfo=`cat /proc/cpuinfo | grep "Revision"|awk -F': ' '{printf $2}'`
model=`cat /sys/firmware/devicetree/base/model`
case ${cpuinfo} in
"0002" )
echo "Revision : 0002 (Model B Rev 1, 256MB)" ;;
"0003" )
echo "Revision : 0003 (Model B Rev 1, ECN0001 (no fuses, D14 removed), 256MB)" ;;
"0004" )
echo "Revision : 0004 (Model B Rev 2, 256MB)" ;;
"0005" )
echo "Revision : 0005 (Model B Rev 2, 256MB)" ;;
"0006" )
echo "Revision : 0006 (Model B Rev 2, 256MB)" ;;
"0007" )
echo "Revision : 0007 (Model A, 256MB)" ;;
"0008" )
echo "Revision : 0008 (Model A, 256MB)" ;;
"0009" )
echo "Revision : 0009 (Model A, 256MB)" ;;
"000d" )
echo "Revision : 000d (Model B Rev 2, 512MB)" ;;
"000e" )
echo "Revision : 000e (Model B Rev 2, 512MB)" ;;
"000f" )
echo "Revision : 000f (Model B Rev 2, 512MB)" ;;
"0010" )
echo "Revision : 0010 (Model B+, 512MB)" ;;
"0013" )
echo "Revision : 0013 (Model B+, 512MB)" ;;
"900032" )
echo "Revision : 900032 (Model B+, 512MB)" ;;
"0011" )
echo "Revision : 0011 (Compute Module, 512MB)" ;;
"0014" )
echo "Revision : 0014 (Compute Module, (Embest, China), 512MB)" ;;
"0012" )
echo "Revision : 0012 (Model A+, 256MB)" ;;
"0015" )
echo "Revision : 0015 (Model A+, (Embest, China), 256MB/512MB)" ;;
"a01041" )
echo "Revision : a01041 (Pi 2 Model B v1.1, (Sony, UK), 1GB)" ;;
"a21041" )
echo "Revision : a01041 (Pi 2 Model B v1.1, (Embest, China), 1GB)" ;;
"a22042" )
echo "Revision : a22042 (Pi 2 Model B v1.2, (Sony, UK), 1GB)" ;;
"900092" )
echo "Revision : 900092 (Pi Zero v1.2, 512MB)" ;;
"900093" )
echo "Revision : 900093 (Pi Zero v1.3, 512MB)" ;;
"9000C1" )
echo "Revision : 9000C1 (Pi Zero W, 512MB)" ;;
"a02082" )
echo "Revision : a02082 (Pi 3 Model B, (Sony, UK), 1GB)" ;;
"a22082" )
echo "Revision : a22082 (Pi 3 Model B, (Embest, China), 1GB)" ;;
"a020d3" )
echo "Revision : a020d3 (Pi 3 Model B+, (Sony, UK), 1GB)" ;;
* )
echo "not a Pi?" ;;
esac
echo "Revision: ${cpuinfo} (${model})"
@wopfel

This comment has been minimized.

Copy link

@wopfel wopfel commented May 25, 2019

Thanks for sharing this. Tried it now using Ansible and it works great.

Is 1GBB just a typo and should read 1GB?

@mhzawadi

This comment has been minimized.

Copy link
Owner Author

@mhzawadi mhzawadi commented May 26, 2019

Thanks @wopfel, I really must get me mac fixed. Have updated.

@mhzawadi

This comment has been minimized.

Copy link
Owner Author

@mhzawadi mhzawadi commented May 26, 2019

Have also added the model from the pi

@wopfel

This comment has been minimized.

Copy link

@wopfel wopfel commented May 29, 2019

Just in addition, here's my ansible playbook (using revision 2 of your script):

- hosts: rasppis
  tasks:
          - name: Get version
            script: ../local-scripts/pi-version.sh
            register: output
            changed_when: False

          - debug:
              msg: System {{ inventory_hostname }} is {{ output.stdout_lines | first }}
$ ansible-playbook playbooks/show-raspberry-pi-version.yml | grep "is Revision"
...
    "msg": "System alarmpi-bba3 is Revision : 000e (Model B Rev 2, 512MB)"
    "msg": "System alarmpi-ab8a is Revision : a020d3 (Pi 3 Model B+, (Sony, UK), 1GBB)"
...

The output could be further processed using sed/awk/whatever. But this is sufficient for a quick view of all pi revisions. Thanks again for sharing this!

By the way, using your script (revision 3) I get line 4: warning: command substitution: ignored null byte in input. This is due to the fact that /sys/firmware/devicetree/base/model ends with a hex 0 value. Didn't know that before...

@rgaudin

This comment has been minimized.

Copy link

@rgaudin rgaudin commented Jun 5, 2019

Hi, there are two duplicates with different values:

  • 0015: Model A+, (Embest, China), 256MB and Model A+, (Embest, China), 512MB
  • a01041: Pi 2 Model B v1.1, (Sony, UK), 1GB) and Pi 2 Model B v1.1, (Embest, China), 1GB)

which one of those is it? Also, there's a typo in the name of 000f, it reads 0009.

@wopfel

This comment has been minimized.

Copy link

@wopfel wopfel commented Jun 5, 2019

According to the official docs, 0015can be both 256/512 MB.

It seems one a01041 should be coded as a21041.

My proposal:

    "0015" )
        echo "Revision : 0015 (Model A+, (Embest, China), 256/512MB)" ;;
    "a01041" )
        echo "Revision : a01041 (Pi 2 Model B v1.1, (Sony, UK), 1GB)" ;;
    "a21041" )
        echo "Revision : a21041 (Pi 2 Model B v1.1, (Embest, China), 1GB)" ;;

Edit: changed revision text to a21041

@rgaudin

This comment has been minimized.

Copy link

@rgaudin rgaudin commented Jun 5, 2019

My proposal:

👍

@mhzawadi

This comment has been minimized.

Copy link
Owner Author

@mhzawadi mhzawadi commented Jun 5, 2019

@wopfel thanks for your comments, have updated the gist.

@rgaudin

This comment has been minimized.

Copy link

@rgaudin rgaudin commented Jun 6, 2019

@mhzawadi, what about the typo in 000f?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment