Hello forum community, I’m currently managing a variety of single-board computers, including Raspberry Pi, Banana Pi.
I need a method to identify the specific model of each device through a script. For Raspberry Pi devices with chips, I’ve been successfully using cat /proc/device-tree/model
or cat /sys/firmware/devicetree/base/model
. However, this approach doesn’t seem to work with Banana Pi devices, as the output is empty. I tried using cat /proc/cmdline
and looking for the board=
entry, but it’s not accurate. For example, for a BPI-P2-Zero, it incorrectly shows bpi-m2z
. Does anyone have any suggestions on how to reliably determine the model of these devices?
#!/bin/bash
# Function to check for Raspberry Pi
checkRaspberryPi() {
local -A revisions=(
["0002"]="Model B Revision 1.0"
["0003"]="Model B Revision 1.0 + ECN0001"
["0004"]="Model B Revision 2.0 (256 MB)"
["0005"]="Model B Revision 2.0 (256 MB)"
["0006"]="Model B Revision 2.0 (256 MB)"
["0007"]="Model A"
["0008"]="Model A"
["0009"]="Model A"
["000d"]="Model B Revision 2.0 (512 MB)"
["000e"]="Model B Revision 2.0 (512 MB)"
["000f"]="Model B Revision 2.0 (512 MB)"
["0010"]="Model B+"
["0013"]="Model B+"
["0011"]="Compute Module"
["0012"]="Model A+"
["a01041"]="Pi 2 Model B"
["a21041"]="Pi 2 Model B"
["900092"]="PiZero 1.2"
["900093"]="PiZero 1.3"
["9000c1"]="PiZero W"
["a02082"]="Pi 3 Model B"
["a22082"]="Pi 3 Model B"
["a32082"]="Pi 3 Model B"
["a52082"]="Pi 3 Model B"
["a020d3"]="Pi 3 Model B+"
["a220a0"]="Compute Module 3"
["a020a0"]="Compute Module 3"
["a02100"]="Compute Module 3+"
["a03111"]="Model 4B Revision 1.1 (1 GB)"
["b03111"]="Model 4B Revision 1.1 (2 GB)"
["c03111"]="Model 4B Revision 1.1 (4 GB)"
)
local rev=$(grep -oP 'Revision\s*:\s*\K[^\s]+' /proc/cpuinfo)
if [[ -v revisions[$rev] ]]; then
echo "Raspberry Pi ${revisions[$rev]}"
return 0
else
if [[ -f /proc/device-tree/model ]]; then
local model=$(< /proc/device-tree/model)
echo "$model"
return 0
else
echo "Unknown Device"
return 1
fi
fi
}
# Function to check for Banana Pi
checkBananaPi() {
local board=$(cat /proc/cmdline | grep -o 'board=[^ ]*' | cut -d'=' -f2)
if [[ -n "$board" ]]; then
echo "Banana Pi, Model: $board"
return 0
else
return 1
fi
}
# First, check if it's a Raspberry Pi
if ! checkRaspberryPi; then
# If it's not a Raspberry Pi, check if it's a Banana Pi
checkBananaPi
fi