memory(), chassis() optimized for raspberry
This commit is contained in:
parent
13793c29bf
commit
0be9e22f4c
@ -780,17 +780,14 @@ function getCpu() {
|
|||||||
result.governor = util.getValue(lines, 'governor') || '';
|
result.governor = util.getValue(lines, 'governor') || '';
|
||||||
|
|
||||||
// Test Raspberry
|
// Test Raspberry
|
||||||
if (result.vendor === 'ARM') {
|
if (result.vendor === 'ARM' && util.isRaspberry()) {
|
||||||
const linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n');
|
const rPIRevision = util.decodePiCpuinfo();
|
||||||
const rPIRevision = util.decodePiCpuinfo(linesRpi);
|
|
||||||
if (rPIRevision.model.toLowerCase().indexOf('raspberry') >= 0) {
|
|
||||||
result.family = result.manufacturer;
|
result.family = result.manufacturer;
|
||||||
result.manufacturer = rPIRevision.manufacturer;
|
result.manufacturer = rPIRevision.manufacturer;
|
||||||
result.brand = rPIRevision.processor;
|
result.brand = rPIRevision.processor;
|
||||||
result.revision = rPIRevision.revisionCode;
|
result.revision = rPIRevision.revisionCode;
|
||||||
result.socket = 'SOC';
|
result.socket = 'SOC';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Test RISC-V
|
// Test RISC-V
|
||||||
if (util.getValue(lines, 'architecture') === 'riscv64') {
|
if (util.getValue(lines, 'architecture') === 'riscv64') {
|
||||||
|
|||||||
@ -401,10 +401,9 @@ function memLayout(callback) {
|
|||||||
try {
|
try {
|
||||||
let stdout = execSync('cat /proc/cpuinfo 2>/dev/null', util.execOptsLinux);
|
let stdout = execSync('cat /proc/cpuinfo 2>/dev/null', util.execOptsLinux);
|
||||||
let lines = stdout.toString().split('\n');
|
let lines = stdout.toString().split('\n');
|
||||||
let model = util.getValue(lines, 'hardware', ':', true).toUpperCase();
|
|
||||||
let version = util.getValue(lines, 'revision', ':', true).toLowerCase();
|
let version = util.getValue(lines, 'revision', ':', true).toLowerCase();
|
||||||
|
|
||||||
if (model === 'BCM2835' || model === 'BCM2708' || model === 'BCM2709' || model === 'BCM2835' || model === 'BCM2837') {
|
if (util.isRaspberry(lines)) {
|
||||||
|
|
||||||
const clockSpeed = {
|
const clockSpeed = {
|
||||||
'0': 400,
|
'0': 400,
|
||||||
|
|||||||
@ -189,7 +189,7 @@ function system(callback) {
|
|||||||
const model = util.getValue(lines, 'model:', ':', true);
|
const model = util.getValue(lines, 'model:', ':', true);
|
||||||
// reference values: https://elinux.org/RPi_HardwareHistory
|
// reference values: https://elinux.org/RPi_HardwareHistory
|
||||||
// https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
|
// https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
|
||||||
if ((result.model === 'BCM2835' || result.model === 'BCM2708' || result.model === 'BCM2709' || result.model === 'BCM2710' || result.model === 'BCM2711' || result.model === 'BCM2836' || result.model === 'BCM2837' || result.model === '') && model.toLowerCase().indexOf('raspberry') >= 0) {
|
if (util.isRaspberry(lines)) {
|
||||||
const rPIRevision = util.decodePiCpuinfo(lines);
|
const rPIRevision = util.decodePiCpuinfo(lines);
|
||||||
result.model = rPIRevision.model;
|
result.model = rPIRevision.model;
|
||||||
result.version = rPIRevision.revisionCode;
|
result.version = rPIRevision.revisionCode;
|
||||||
@ -504,16 +504,8 @@ function baseboard(callback) {
|
|||||||
result.memSlots = util.toInt(util.getValue(lines, 'Number Of Devices')) || null;
|
result.memSlots = util.toInt(util.getValue(lines, 'Number Of Devices')) || null;
|
||||||
|
|
||||||
// raspberry
|
// raspberry
|
||||||
let linesRpi = '';
|
if (util.isRaspberry()) {
|
||||||
try {
|
const rpi = util.decodePiCpuinfo();
|
||||||
linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n');
|
|
||||||
} catch (e) {
|
|
||||||
util.noop();
|
|
||||||
}
|
|
||||||
if (linesRpi) {
|
|
||||||
const hardware = util.getValue(linesRpi, 'hardware');
|
|
||||||
if (hardware.startsWith('BCM')) {
|
|
||||||
const rpi = util.decodePiCpuinfo(linesRpi);
|
|
||||||
result.manufacturer = rpi.manufacturer;
|
result.manufacturer = rpi.manufacturer;
|
||||||
result.model = 'Raspberry Pi';
|
result.model = 'Raspberry Pi';
|
||||||
result.serial = rpi.serial;
|
result.serial = rpi.serial;
|
||||||
@ -521,7 +513,6 @@ function baseboard(callback) {
|
|||||||
result.memMax = os.totalmem();
|
result.memMax = os.totalmem();
|
||||||
result.memSlots = 0;
|
result.memSlots = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
|
|||||||
43
lib/util.js
43
lib/util.js
@ -635,7 +635,7 @@ function smartMonToolsInstalled() {
|
|||||||
return _smartMonToolsInstalled;
|
return _smartMonToolsInstalled;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRaspberry() {
|
function isRaspberry(cpuinfo) {
|
||||||
const PI_MODEL_NO = [
|
const PI_MODEL_NO = [
|
||||||
'BCM2708',
|
'BCM2708',
|
||||||
'BCM2709',
|
'BCM2709',
|
||||||
@ -647,11 +647,9 @@ function isRaspberry() {
|
|||||||
'BCM2837',
|
'BCM2837',
|
||||||
'BCM2837B0'
|
'BCM2837B0'
|
||||||
];
|
];
|
||||||
let cpuinfo = [];
|
|
||||||
|
|
||||||
if (_rpi_cpuinfo !== null) {
|
if (_rpi_cpuinfo !== null) {
|
||||||
cpuinfo = _rpi_cpuinfo;
|
cpuinfo = _rpi_cpuinfo;
|
||||||
} else {
|
} else if (cpuinfo === null) {
|
||||||
try {
|
try {
|
||||||
cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
|
cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
|
||||||
_rpi_cpuinfo = cpuinfo;
|
_rpi_cpuinfo = cpuinfo;
|
||||||
@ -884,11 +882,14 @@ function decodePiCpuinfo(lines) {
|
|||||||
|
|
||||||
if (_rpi_cpuinfo === null) {
|
if (_rpi_cpuinfo === null) {
|
||||||
_rpi_cpuinfo = lines;
|
_rpi_cpuinfo = lines;
|
||||||
|
} else if (lines === null) {
|
||||||
|
lines = _rpi_cpuinfo;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
|
// https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
|
||||||
|
|
||||||
const oldRevisionCodes = {
|
const oldRevisionCodes = {
|
||||||
'0002': {
|
'0002': {
|
||||||
type: 'B',
|
type: 'B',
|
||||||
revision: '1.0',
|
revision: '1.0',
|
||||||
@ -1008,24 +1009,24 @@ function decodePiCpuinfo(lines) {
|
|||||||
manufacturer: '512MB Embest',
|
manufacturer: '512MB Embest',
|
||||||
processor: 'BCM2835'
|
processor: 'BCM2835'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const processorList = [
|
const processorList = [
|
||||||
'BCM2835',
|
'BCM2835',
|
||||||
'BCM2836',
|
'BCM2836',
|
||||||
'BCM2837',
|
'BCM2837',
|
||||||
'BCM2711',
|
'BCM2711',
|
||||||
'BCM2712',
|
'BCM2712',
|
||||||
];
|
];
|
||||||
const manufacturerList = [
|
const manufacturerList = [
|
||||||
'Sony UK',
|
'Sony UK',
|
||||||
'Egoman',
|
'Egoman',
|
||||||
'Embest',
|
'Embest',
|
||||||
'Sony Japan',
|
'Sony Japan',
|
||||||
'Embest',
|
'Embest',
|
||||||
'Stadium'
|
'Stadium'
|
||||||
];
|
];
|
||||||
const typeList = {
|
const typeList = {
|
||||||
'00': 'A',
|
'00': 'A',
|
||||||
'01': 'B',
|
'01': 'B',
|
||||||
'02': 'A+',
|
'02': 'A+',
|
||||||
@ -1051,14 +1052,14 @@ function decodePiCpuinfo(lines) {
|
|||||||
'18': 'CM5',
|
'18': 'CM5',
|
||||||
'19': '500',
|
'19': '500',
|
||||||
'1a': 'CM5 Lite',
|
'1a': 'CM5 Lite',
|
||||||
};
|
};
|
||||||
|
|
||||||
const revisionCode = getValue(lines, 'revision', ':', true);
|
const revisionCode = getValue(lines, 'revision', ':', true);
|
||||||
const model = getValue(lines, 'model:', ':', true);
|
const model = getValue(lines, 'model:', ':', true);
|
||||||
const serial = getValue(lines, 'serial', ':', true);
|
const serial = getValue(lines, 'serial', ':', true);
|
||||||
|
|
||||||
let result = {};
|
let result = {};
|
||||||
if ({}.hasOwnProperty.call(oldRevisionCodes, revisionCode)) {
|
if ({}.hasOwnProperty.call(oldRevisionCodes, revisionCode)) {
|
||||||
// old revision codes
|
// old revision codes
|
||||||
result = {
|
result = {
|
||||||
model,
|
model,
|
||||||
@ -1071,7 +1072,7 @@ function decodePiCpuinfo(lines) {
|
|||||||
revision: oldRevisionCodes[revisionCode].revision,
|
revision: oldRevisionCodes[revisionCode].revision,
|
||||||
};
|
};
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// new revision code
|
// new revision code
|
||||||
const revision = ('00000000' + getValue(lines, 'revision', ':', true).toLowerCase()).substr(-8);
|
const revision = ('00000000' + getValue(lines, 'revision', ':', true).toLowerCase()).substr(-8);
|
||||||
const memSizeCode = parseInt(hex2bin(revision.substr(2, 1)).substr(5, 3), 2) || 0;
|
const memSizeCode = parseInt(hex2bin(revision.substr(2, 1)).substr(5, 3), 2) || 0;
|
||||||
@ -1090,8 +1091,8 @@ function decodePiCpuinfo(lines) {
|
|||||||
type: {}.hasOwnProperty.call(typeList, typeCode) ? typeList[typeCode] : '',
|
type: {}.hasOwnProperty.call(typeList, typeCode) ? typeList[typeCode] : '',
|
||||||
revision: '1.' + revision.substr(7, 1),
|
revision: '1.' + revision.substr(7, 1),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRpiGpu() {
|
function getRpiGpu() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user