Skip to content

Commit 87af870

Browse files
committed
system: fix RPI detection with recent RPI kernels
The 'Hardware' field has been removed from the output of '/proc/cpuinfo' after [1], so the setup script will not correctly identify it's running on a Raspberry PI. Use '/proc/device-tree/compatible' to check whether we're on a Raspberry Pi, the same method used for other SBCs. Model calculation based on the Revision field from '/proc/cpuinfo' needs to be run in 2 places, so the code has been put in a separate function. [1] pelwell/linux@17804c2
1 parent c10045c commit 87af870

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

scriptmodules/system.sh

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -376,37 +376,42 @@ function get_rpi_video() {
376376
export PKG_CONFIG_PATH="$pkgconfig"
377377
}
378378

379+
function get_rpi_model() {
380+
# calculated based on the information from https://github.com/AndrewFromMelbourne/raspberry_pi_revision
381+
# see also https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-revision-codes
382+
local rev="0x$(sed -n '/^Revision/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo)"
383+
# if bit 23 is not set, we are on a rpi1 (bit 23 means the revision is a bitfield)
384+
if [[ $((($rev >> 23) & 1)) -eq 0 ]]; then
385+
__platform="rpi1"
386+
else
387+
# if bit 23 is set, get the cpu from bits 12-15
388+
local cpu=$((($rev >> 12) & 15))
389+
case $cpu in
390+
0)
391+
__platform="rpi1"
392+
;;
393+
1)
394+
__platform="rpi2"
395+
;;
396+
2)
397+
__platform="rpi3"
398+
;;
399+
3)
400+
__platform="rpi4"
401+
;;
402+
4)
403+
__platform="rpi5"
404+
;;
405+
esac
406+
fi
407+
}
379408
function get_platform() {
380409
local architecture="$(uname --machine)"
381410
if [[ -z "$__platform" ]]; then
382411
case "$(sed -n '/^Hardware/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo)" in
383412
BCM*)
384-
# calculated based on information from https://github.com/AndrewFromMelbourne/raspberry_pi_revision
385-
local rev="0x$(sed -n '/^Revision/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo)"
386-
# if bit 23 is not set, we are on a rpi1 (bit 23 means the revision is a bitfield)
387-
if [[ $((($rev >> 23) & 1)) -eq 0 ]]; then
388-
__platform="rpi1"
389-
else
390-
# if bit 23 is set, get the cpu from bits 12-15
391-
local cpu=$((($rev >> 12) & 15))
392-
case $cpu in
393-
0)
394-
__platform="rpi1"
395-
;;
396-
1)
397-
__platform="rpi2"
398-
;;
399-
2)
400-
__platform="rpi3"
401-
;;
402-
3)
403-
__platform="rpi4"
404-
;;
405-
4)
406-
__platform="rpi5"
407-
;;
408-
esac
409-
fi
413+
# RPI kernels before 2023-11-24 print a 'Hardware: BCM2835' line
414+
get_rpi_model
410415
;;
411416
*ODROIDC)
412417
__platform="odroid-c1"
@@ -434,6 +439,9 @@ function get_platform() {
434439
# refer to the nv.sh script in the L4T DTS for a similar implementation
435440
if [[ -e "/proc/device-tree/compatible" ]]; then
436441
case "$(tr -d '\0' < /proc/device-tree/compatible)" in
442+
*raspberrypi*)
443+
get_rpi_model
444+
;;
437445
*tegra186*)
438446
__platform="tegra-x2"
439447
;;

0 commit comments

Comments
 (0)