memory(), chassis() optimized for raspberry
This commit is contained in:
parent
13793c29bf
commit
0be9e22f4c
17
lib/cpu.js
17
lib/cpu.js
@ -780,16 +780,13 @@ function getCpu() {
|
||||
result.governor = util.getValue(lines, 'governor') || '';
|
||||
|
||||
// Test Raspberry
|
||||
if (result.vendor === 'ARM') {
|
||||
const linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n');
|
||||
const rPIRevision = util.decodePiCpuinfo(linesRpi);
|
||||
if (rPIRevision.model.toLowerCase().indexOf('raspberry') >= 0) {
|
||||
result.family = result.manufacturer;
|
||||
result.manufacturer = rPIRevision.manufacturer;
|
||||
result.brand = rPIRevision.processor;
|
||||
result.revision = rPIRevision.revisionCode;
|
||||
result.socket = 'SOC';
|
||||
}
|
||||
if (result.vendor === 'ARM' && util.isRaspberry()) {
|
||||
const rPIRevision = util.decodePiCpuinfo();
|
||||
result.family = result.manufacturer;
|
||||
result.manufacturer = rPIRevision.manufacturer;
|
||||
result.brand = rPIRevision.processor;
|
||||
result.revision = rPIRevision.revisionCode;
|
||||
result.socket = 'SOC';
|
||||
}
|
||||
|
||||
// Test RISC-V
|
||||
|
||||
@ -401,10 +401,9 @@ function memLayout(callback) {
|
||||
try {
|
||||
let stdout = execSync('cat /proc/cpuinfo 2>/dev/null', util.execOptsLinux);
|
||||
let lines = stdout.toString().split('\n');
|
||||
let model = util.getValue(lines, 'hardware', ':', true).toUpperCase();
|
||||
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 = {
|
||||
'0': 400,
|
||||
|
||||
@ -189,7 +189,7 @@ function system(callback) {
|
||||
const model = util.getValue(lines, 'model:', ':', true);
|
||||
// reference values: https://elinux.org/RPi_HardwareHistory
|
||||
// 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);
|
||||
result.model = rPIRevision.model;
|
||||
result.version = rPIRevision.revisionCode;
|
||||
@ -504,23 +504,14 @@ function baseboard(callback) {
|
||||
result.memSlots = util.toInt(util.getValue(lines, 'Number Of Devices')) || null;
|
||||
|
||||
// raspberry
|
||||
let linesRpi = '';
|
||||
try {
|
||||
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.model = 'Raspberry Pi';
|
||||
result.serial = rpi.serial;
|
||||
result.version = rpi.type + ' - ' + rpi.revision;
|
||||
result.memMax = os.totalmem();
|
||||
result.memSlots = 0;
|
||||
}
|
||||
if (util.isRaspberry()) {
|
||||
const rpi = util.decodePiCpuinfo();
|
||||
result.manufacturer = rpi.manufacturer;
|
||||
result.model = 'Raspberry Pi';
|
||||
result.serial = rpi.serial;
|
||||
result.version = rpi.type + ' - ' + rpi.revision;
|
||||
result.memMax = os.totalmem();
|
||||
result.memSlots = 0;
|
||||
}
|
||||
|
||||
if (callback) { callback(result); }
|
||||
|
||||
413
lib/util.js
413
lib/util.js
@ -635,7 +635,7 @@ function smartMonToolsInstalled() {
|
||||
return _smartMonToolsInstalled;
|
||||
}
|
||||
|
||||
function isRaspberry() {
|
||||
function isRaspberry(cpuinfo) {
|
||||
const PI_MODEL_NO = [
|
||||
'BCM2708',
|
||||
'BCM2709',
|
||||
@ -647,11 +647,9 @@ function isRaspberry() {
|
||||
'BCM2837',
|
||||
'BCM2837B0'
|
||||
];
|
||||
let cpuinfo = [];
|
||||
|
||||
if (_rpi_cpuinfo !== null) {
|
||||
cpuinfo = _rpi_cpuinfo;
|
||||
} else {
|
||||
} else if (cpuinfo === null) {
|
||||
try {
|
||||
cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
|
||||
_rpi_cpuinfo = cpuinfo;
|
||||
@ -884,214 +882,217 @@ function decodePiCpuinfo(lines) {
|
||||
|
||||
if (_rpi_cpuinfo === null) {
|
||||
_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 = {
|
||||
'0002': {
|
||||
type: 'B',
|
||||
revision: '1.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0003': {
|
||||
type: 'B',
|
||||
revision: '1.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0004': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0005': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Qisda',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0006': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0007': {
|
||||
type: 'A',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0008': {
|
||||
type: 'A',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0009': {
|
||||
type: 'A',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Qisda',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'000d': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 512,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'000e': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 512,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'000f': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 512,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0010': {
|
||||
type: 'B+',
|
||||
revision: '1.2',
|
||||
memory: 512,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0011': {
|
||||
type: 'CM1',
|
||||
revision: '1.0',
|
||||
memory: 512,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0012': {
|
||||
type: 'A+',
|
||||
revision: '1.1',
|
||||
memory: 256,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0013': {
|
||||
type: 'B+',
|
||||
revision: '1.2',
|
||||
memory: 512,
|
||||
manufacturer: 'Embest',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0014': {
|
||||
type: 'CM1',
|
||||
revision: '1.0',
|
||||
memory: 512,
|
||||
manufacturer: 'Embest',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0015': {
|
||||
type: 'A+',
|
||||
revision: '1.1',
|
||||
memory: 256,
|
||||
manufacturer: '512MB Embest',
|
||||
processor: 'BCM2835'
|
||||
}
|
||||
const oldRevisionCodes = {
|
||||
'0002': {
|
||||
type: 'B',
|
||||
revision: '1.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0003': {
|
||||
type: 'B',
|
||||
revision: '1.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0004': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0005': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Qisda',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0006': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0007': {
|
||||
type: 'A',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0008': {
|
||||
type: 'A',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0009': {
|
||||
type: 'A',
|
||||
revision: '2.0',
|
||||
memory: 256,
|
||||
manufacturer: 'Qisda',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'000d': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 512,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'000e': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 512,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'000f': {
|
||||
type: 'B',
|
||||
revision: '2.0',
|
||||
memory: 512,
|
||||
manufacturer: 'Egoman',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0010': {
|
||||
type: 'B+',
|
||||
revision: '1.2',
|
||||
memory: 512,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0011': {
|
||||
type: 'CM1',
|
||||
revision: '1.0',
|
||||
memory: 512,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0012': {
|
||||
type: 'A+',
|
||||
revision: '1.1',
|
||||
memory: 256,
|
||||
manufacturer: 'Sony UK',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0013': {
|
||||
type: 'B+',
|
||||
revision: '1.2',
|
||||
memory: 512,
|
||||
manufacturer: 'Embest',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0014': {
|
||||
type: 'CM1',
|
||||
revision: '1.0',
|
||||
memory: 512,
|
||||
manufacturer: 'Embest',
|
||||
processor: 'BCM2835'
|
||||
},
|
||||
'0015': {
|
||||
type: 'A+',
|
||||
revision: '1.1',
|
||||
memory: 256,
|
||||
manufacturer: '512MB Embest',
|
||||
processor: 'BCM2835'
|
||||
}
|
||||
};
|
||||
|
||||
const processorList = [
|
||||
'BCM2835',
|
||||
'BCM2836',
|
||||
'BCM2837',
|
||||
'BCM2711',
|
||||
'BCM2712',
|
||||
];
|
||||
const manufacturerList = [
|
||||
'Sony UK',
|
||||
'Egoman',
|
||||
'Embest',
|
||||
'Sony Japan',
|
||||
'Embest',
|
||||
'Stadium'
|
||||
];
|
||||
const typeList = {
|
||||
'00': 'A',
|
||||
'01': 'B',
|
||||
'02': 'A+',
|
||||
'03': 'B+',
|
||||
'04': '2B',
|
||||
'05': 'Alpha (early prototype)',
|
||||
'06': 'CM1',
|
||||
'08': '3B',
|
||||
'09': 'Zero',
|
||||
'0a': 'CM3',
|
||||
'0c': 'Zero W',
|
||||
'0d': '3B+',
|
||||
'0e': '3A+',
|
||||
'0f': 'Internal use only',
|
||||
'10': 'CM3+',
|
||||
'11': '4B',
|
||||
'12': 'Zero 2 W',
|
||||
'13': '400',
|
||||
'14': 'CM4',
|
||||
'15': 'CM4S',
|
||||
'16': 'Internal use only',
|
||||
'17': '5',
|
||||
'18': 'CM5',
|
||||
'19': '500',
|
||||
'1a': 'CM5 Lite',
|
||||
};
|
||||
|
||||
const revisionCode = getValue(lines, 'revision', ':', true);
|
||||
const model = getValue(lines, 'model:', ':', true);
|
||||
const serial = getValue(lines, 'serial', ':', true);
|
||||
|
||||
let result = {};
|
||||
if ({}.hasOwnProperty.call(oldRevisionCodes, revisionCode)) {
|
||||
// old revision codes
|
||||
result = {
|
||||
model,
|
||||
serial,
|
||||
revisionCode,
|
||||
memory: oldRevisionCodes[revisionCode].memory,
|
||||
manufacturer: oldRevisionCodes[revisionCode].manufacturer,
|
||||
processor: oldRevisionCodes[revisionCode].processor,
|
||||
type: oldRevisionCodes[revisionCode].type,
|
||||
revision: oldRevisionCodes[revisionCode].revision,
|
||||
};
|
||||
|
||||
const processorList = [
|
||||
'BCM2835',
|
||||
'BCM2836',
|
||||
'BCM2837',
|
||||
'BCM2711',
|
||||
'BCM2712',
|
||||
];
|
||||
const manufacturerList = [
|
||||
'Sony UK',
|
||||
'Egoman',
|
||||
'Embest',
|
||||
'Sony Japan',
|
||||
'Embest',
|
||||
'Stadium'
|
||||
];
|
||||
const typeList = {
|
||||
'00': 'A',
|
||||
'01': 'B',
|
||||
'02': 'A+',
|
||||
'03': 'B+',
|
||||
'04': '2B',
|
||||
'05': 'Alpha (early prototype)',
|
||||
'06': 'CM1',
|
||||
'08': '3B',
|
||||
'09': 'Zero',
|
||||
'0a': 'CM3',
|
||||
'0c': 'Zero W',
|
||||
'0d': '3B+',
|
||||
'0e': '3A+',
|
||||
'0f': 'Internal use only',
|
||||
'10': 'CM3+',
|
||||
'11': '4B',
|
||||
'12': 'Zero 2 W',
|
||||
'13': '400',
|
||||
'14': 'CM4',
|
||||
'15': 'CM4S',
|
||||
'16': 'Internal use only',
|
||||
'17': '5',
|
||||
'18': 'CM5',
|
||||
'19': '500',
|
||||
'1a': 'CM5 Lite',
|
||||
} else {
|
||||
// new revision code
|
||||
const revision = ('00000000' + getValue(lines, 'revision', ':', true).toLowerCase()).substr(-8);
|
||||
const memSizeCode = parseInt(hex2bin(revision.substr(2, 1)).substr(5, 3), 2) || 0;
|
||||
const manufacturer = manufacturerList[parseInt(revision.substr(3, 1), 10)];
|
||||
const processor = processorList[parseInt(revision.substr(4, 1), 10)];
|
||||
const typeCode = revision.substr(5, 2);
|
||||
|
||||
|
||||
result = {
|
||||
model,
|
||||
serial,
|
||||
revisionCode,
|
||||
memory: 256 * Math.pow(2, memSizeCode),
|
||||
manufacturer,
|
||||
processor,
|
||||
type: {}.hasOwnProperty.call(typeList, typeCode) ? typeList[typeCode] : '',
|
||||
revision: '1.' + revision.substr(7, 1),
|
||||
};
|
||||
|
||||
const revisionCode = getValue(lines, 'revision', ':', true);
|
||||
const model = getValue(lines, 'model:', ':', true);
|
||||
const serial = getValue(lines, 'serial', ':', true);
|
||||
|
||||
let result = {};
|
||||
if ({}.hasOwnProperty.call(oldRevisionCodes, revisionCode)) {
|
||||
// old revision codes
|
||||
result = {
|
||||
model,
|
||||
serial,
|
||||
revisionCode,
|
||||
memory: oldRevisionCodes[revisionCode].memory,
|
||||
manufacturer: oldRevisionCodes[revisionCode].manufacturer,
|
||||
processor: oldRevisionCodes[revisionCode].processor,
|
||||
type: oldRevisionCodes[revisionCode].type,
|
||||
revision: oldRevisionCodes[revisionCode].revision,
|
||||
};
|
||||
|
||||
} else {
|
||||
// new revision code
|
||||
const revision = ('00000000' + getValue(lines, 'revision', ':', true).toLowerCase()).substr(-8);
|
||||
const memSizeCode = parseInt(hex2bin(revision.substr(2, 1)).substr(5, 3), 2) || 0;
|
||||
const manufacturer = manufacturerList[parseInt(revision.substr(3, 1), 10)];
|
||||
const processor = processorList[parseInt(revision.substr(4, 1), 10)];
|
||||
const typeCode = revision.substr(5, 2);
|
||||
|
||||
|
||||
result = {
|
||||
model,
|
||||
serial,
|
||||
revisionCode,
|
||||
memory: 256 * Math.pow(2, memSizeCode),
|
||||
manufacturer,
|
||||
processor,
|
||||
type: {}.hasOwnProperty.call(typeList, typeCode) ? typeList[typeCode] : '',
|
||||
revision: '1.' + revision.substr(7, 1),
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getRpiGpu() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user