Skip to content

Commit

Permalink
Raspberry Pi 5 detection
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Oct 21, 2023
1 parent aef8a08 commit 3a2f88b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
14 changes: 14 additions & 0 deletions lib/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,20 @@ const AMDBaseFrequencies = {
'5800X': '3.8',
'5900X': '3.7',
'5950X': '3.4',
'5945WX': '4.1',
'5955WX': '4.0',
'5965WX': '3.8',
'5975WX': '3.6',
'5995WX': '2.7',

'7960X': '4.2',
'7970X': '4.0',
'7980X': '3.2',

'7965WX': '4.2',
'7975WX': '4.0',
'7985WX': '3.2',
'7995WX': '2.5',

// ZEN4
'9754': '2.25',
Expand Down
2 changes: 1 addition & 1 deletion lib/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ function graphics(callback) {
if (lines.length > 1 && stdout.toString().indexOf('gpu=') >= -1) {
result.controllers.push({
vendor: 'Broadcom',
model: 'VideoCore IV',
model: util.getRpiGpu(),
bus: '',
vram: util.getValue(lines, 'gpu', '=').replace('M', ''),
vramDynamic: true
Expand Down
45 changes: 40 additions & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let _cores = 0;
let wmicPath = '';
let codepage = '';
let _smartMonToolsInstalled = null;
let _rpi_cpuinfo = null;

const WINDIR = process.env.WINDIR || 'C:\\Windows';

Expand Down Expand Up @@ -602,17 +603,25 @@ function isRaspberry() {
'BCM2709',
'BCM2710',
'BCM2711',
'BCM2712',
'BCM2835',
'BCM2836',
'BCM2837',
'BCM2837B0'
];
let cpuinfo = [];
try {
cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
} catch (e) {
return false;

if (_rpi_cpuinfo !== null) {
cpuinfo = _rpi_cpuinfo;
} else {
try {
cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
_rpi_cpuinfo = cpuinfo;
} catch (e) {
return false;
}
}

const hardware = getValue(cpuinfo, 'hardware');
return (hardware && PI_MODEL_NO.indexOf(hardware) > -1);
}
Expand Down Expand Up @@ -819,6 +828,10 @@ function getFilesInPath(source) {

function decodePiCpuinfo(lines) {

if (_rpi_cpuinfo === null) {
_rpi_cpuinfo = lines;
}

// https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md

const oldRevisionCodes = {
Expand Down Expand Up @@ -948,6 +961,7 @@ function decodePiCpuinfo(lines) {
'BCM2836',
'BCM2837',
'BCM2711',
'BCM2712',
];
const manufacturerList = [
'Sony UK',
Expand Down Expand Up @@ -977,7 +991,8 @@ function decodePiCpuinfo(lines) {
'12': 'Zero 2 W',
'13': '400',
'14': 'CM4',
'15': 'CM4S'
'15': 'CM4S',
'17': '5B',
};

const revisionCode = getValue(lines, 'revision', ':', true);
Expand Down Expand Up @@ -1021,6 +1036,25 @@ function decodePiCpuinfo(lines) {
return result;
}

function getRpiGpu() {
let cpuinfo = null;
if (_rpi_cpuinfo !== null) {
cpuinfo = _rpi_cpuinfo;
} else {
try {
cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
_rpi_cpuinfo = cpuinfo;
} catch (e) {
return false;
}
}

const rpi = decodePiCpuinfo(cpuinfo);
if (rpi.type === '4B' || rpi.type === 'CM4' || rpi.type === 'CM4S' || rpi.type === '400') { return 'VideoCore VI'; }
if (rpi.type === '5B') { return 'VideoCore VII'; }
return 'VideoCore IV';
}

function promiseAll(promises) {
const resolvingPromises = promises.map(function (promise) {
return new Promise(function (resolve) {
Expand Down Expand Up @@ -1291,6 +1325,7 @@ exports.isRaspbian = isRaspbian;
exports.sanitizeShellString = sanitizeShellString;
exports.isPrototypePolluted = isPrototypePolluted;
exports.decodePiCpuinfo = decodePiCpuinfo;
exports.getRpiGpu = getRpiGpu;
exports.promiseAll = promiseAll;
exports.promisify = promisify;
exports.promisifySave = promisifySave;
Expand Down

0 comments on commit 3a2f88b

Please sign in to comment.