From 3a2f88bcbcd8d16a2090ab500f7112b7fa68b947 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sat, 21 Oct 2023 13:00:21 +0200 Subject: [PATCH] Raspberry Pi 5 detection --- lib/cpu.js | 14 ++++++++++++++ lib/graphics.js | 2 +- lib/util.js | 45 ++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/lib/cpu.js b/lib/cpu.js index ae2d61c..79b64ac 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -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', diff --git a/lib/graphics.js b/lib/graphics.js index 95a71e1..22285cf 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -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 diff --git a/lib/util.js b/lib/util.js index 76d4bf0..e7e25a2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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'; @@ -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); } @@ -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 = { @@ -948,6 +961,7 @@ function decodePiCpuinfo(lines) { 'BCM2836', 'BCM2837', 'BCM2711', + 'BCM2712', ]; const manufacturerList = [ 'Sony UK', @@ -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); @@ -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) { @@ -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;