@@ -5,7 +5,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
55Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
66exports . RaspberryPiInfo = exports . revisions = void 0 ;
77const fs_1 = __importDefault ( require ( "fs" ) ) ;
8- /** @see https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#new-style-revision-codes */
8+ /** Lookup table for model type field (bits 4-11) */
9+ const modelTypes = {
10+ 0x00 : 'A' ,
11+ 0x01 : 'B' ,
12+ 0x02 : 'A+' ,
13+ 0x03 : 'B+' ,
14+ 0x04 : '2B' ,
15+ 0x05 : 'Alpha' ,
16+ 0x06 : 'CM1' ,
17+ 0x08 : '3B' ,
18+ 0x09 : 'Zero' ,
19+ 0x0a : 'CM3' ,
20+ 0x0c : 'Zero W' ,
21+ 0x0d : '3B+' ,
22+ 0x0e : '3A+' ,
23+ 0x10 : 'CM3+' ,
24+ 0x11 : '4B' ,
25+ 0x12 : 'Zero 2 W' ,
26+ 0x13 : 'Pi 400' ,
27+ 0x14 : 'CM4' ,
28+ 0x15 : 'CM4S' ,
29+ 0x17 : '5' ,
30+ 0x18 : 'CM5' ,
31+ 0x19 : '500' ,
32+ 0x1a : 'CM5 Lite' ,
33+ } ;
34+ /** Lookup table for processor field (bits 12-15) */
35+ const processorTypes = {
36+ 0 : 'BCM2835' ,
37+ 1 : 'BCM2836' ,
38+ 2 : 'BCM2837' ,
39+ 3 : 'BCM2711' ,
40+ 4 : 'BCM2712' ,
41+ } ;
42+ /** Lookup table for manufacturer field (bits 16-19) */
43+ const manufacturerTypes = {
44+ 0 : 'Sony UK' ,
45+ 1 : 'Egoman' ,
46+ 2 : 'Embest' ,
47+ 3 : 'Sony Japan' ,
48+ 4 : 'Embest' ,
49+ 5 : 'Stadium' ,
50+ } ;
51+ /** Lookup table for memory size field (bits 20-22) */
52+ const memoryTypes = {
53+ 0 : '256MB' ,
54+ 1 : '512MB' ,
55+ 2 : '1GB' ,
56+ 3 : '2GB' ,
57+ 4 : '4GB' ,
58+ 5 : '8GB' ,
59+ 6 : '16GB' ,
60+ } ;
61+ /** @see https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#new-style-revision-codes-in-use */
962exports . revisions = {
1063 '900021' : { model : 'A+' , ram : '512MB' , manufacturer : 'Sony UK' } ,
1164 '900032' : { model : 'B+' , ram : '512MB' , manufacturer : 'Sony UK' } ,
@@ -50,7 +103,18 @@ exports.revisions = {
50103 'd03140' : { model : 'CM4' , ram : '8GB' , manufacturer : 'Sony UK' } ,
51104 '902120' : { model : 'Zero 2 W' , ram : '512MB' , manufacturer : 'Sony UK' } ,
52105 'c04170' : { model : '5' , ram : '4GB' , manufacturer : 'Sony UK' } ,
53- 'd04170' : { model : '5' , ram : '8GB' , manufacturer : 'Sony UK' }
106+ 'd04170' : { model : '5' , ram : '8GB' , manufacturer : 'Sony UK' } ,
107+ 'b04171' : { model : '5' , revision : '1.1' , ram : '2GB' , manufacturer : 'Sony UK' } ,
108+ 'c04171' : { model : '5' , revision : '1.1' , ram : '4GB' , manufacturer : 'Sony UK' } ,
109+ 'd04171' : { model : '5' , revision : '1.1' , ram : '8GB' , manufacturer : 'Sony UK' } ,
110+ 'e04171' : { model : '5' , revision : '1.1' , ram : '16GB' , manufacturer : 'Sony UK' } ,
111+ 'b04180' : { model : 'CM5' , revision : '1.0' , ram : '2GB' , manufacturer : 'Sony UK' } ,
112+ 'c04180' : { model : 'CM5' , revision : '1.0' , ram : '4GB' , manufacturer : 'Sony UK' } ,
113+ 'd04180' : { model : 'CM5' , revision : '1.0' , ram : '8GB' , manufacturer : 'Sony UK' } ,
114+ 'd04190' : { model : '500' , revision : '1.0' , ram : '8GB' , manufacturer : 'Sony UK' } ,
115+ 'b041a0' : { model : 'CM5 Lite' , revision : '1.0' , ram : '2GB' , manufacturer : 'Sony UK' } ,
116+ 'c041a0' : { model : 'CM5 Lite' , revision : '1.0' , ram : '4GB' , manufacturer : 'Sony UK' } ,
117+ 'd041a0' : { model : 'CM5 Lite' , revision : '1.0' , ram : '8GB' , manufacturer : 'Sony UK' } ,
54118} ;
55119class RaspberryPiInfo {
56120 constructor ( additionalRevisions = { } , raspberryPiBaseName = 'Raspberry Pi' ) {
@@ -72,24 +136,74 @@ class RaspberryPiInfo {
72136 if ( revisionCode === null ) {
73137 return info ;
74138 }
139+ // First try the static revision map
75140 const revision = this . revisions [ revisionCode ] ;
76- if ( ! revision ) {
141+ if ( revision ) {
142+ info . isRaspberry = true ;
143+ info . model = revision . model ;
144+ info . fullModelName = `${ this . raspberryPiBaseName } ${ info . model } ` ;
145+ info . fullModelNameWithRam = `${ this . raspberryPiBaseName } ${ info . model } - ${ revision . ram } ` ;
146+ info . ram = revision . ram ;
147+ info . manufacturer = revision . manufacturer ;
148+ info . revisionCode = revisionCode ;
149+ return info ;
150+ }
151+ // Fallback: decode the revision code using bit fields
152+ const decoded = this . decodeRevisionCode ( revisionCode ) ;
153+ if ( decoded ) {
154+ info . isRaspberry = true ;
155+ info . model = decoded . model ;
156+ info . fullModelName = `${ this . raspberryPiBaseName } ${ info . model } ` ;
157+ info . fullModelNameWithRam = `${ this . raspberryPiBaseName } ${ info . model } - ${ decoded . ram } ` ;
158+ info . ram = decoded . ram ;
159+ info . manufacturer = decoded . manufacturer ;
160+ info . revisionCode = revisionCode ;
77161 return info ;
78162 }
79- info . isRaspberry = true ;
80- info . model = revision . model ;
81- info . fullModelName = `${ this . raspberryPiBaseName } ${ info . model } ` ;
82- info . fullModelNameWithRam = `${ this . raspberryPiBaseName } ${ info . model } - ${ revision . ram } ` ;
83- info . ram = revision . ram ;
84- info . manufacturer = revision . manufacturer ;
85- info . revisionCode = revisionCode ;
86163 return info ;
87164 }
88165 catch ( e ) {
89166 // cpuinfo not found, prob not rpi
90167 return info ;
91168 }
92169 }
170+ /**
171+ * Decode a new-style revision code by extracting bit fields.
172+ * This handles unknown revision codes that aren't in the static map,
173+ * so new board revisions are automatically supported.
174+ *
175+ * Bit layout (new-style, bit 23 = 1):
176+ * Bits 0-3: Board revision
177+ * Bits 4-11: Model type
178+ * Bits 12-15: Processor
179+ * Bits 16-19: Manufacturer
180+ * Bits 20-22: Memory size
181+ * Bit 23: New flag (must be 1)
182+ *
183+ * @see https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#new-style-revision-codes-in-use
184+ */
185+ decodeRevisionCode ( revisionCode ) {
186+ var _a , _b ;
187+ const code = parseInt ( revisionCode , 16 ) ;
188+ if ( isNaN ( code ) ) {
189+ return null ;
190+ }
191+ // Check bit 23 — must be 1 for new-style revision codes
192+ const isNewStyle = ( code >> 23 ) & 0x1 ;
193+ if ( ! isNewStyle ) {
194+ return null ;
195+ }
196+ const modelType = ( code >> 4 ) & 0xff ;
197+ const manufacturerId = ( code >> 16 ) & 0xf ;
198+ const memoryId = ( code >> 20 ) & 0x7 ;
199+ const model = modelTypes [ modelType ] ;
200+ if ( ! model ) {
201+ return null ;
202+ }
203+ const ram = ( _a = memoryTypes [ memoryId ] ) !== null && _a !== void 0 ? _a : 'Unknown' ;
204+ const manufacturer = ( _b = manufacturerTypes [ manufacturerId ] ) !== null && _b !== void 0 ? _b : 'Unknown' ;
205+ return { model, ram, manufacturer } ;
206+ }
93207 readRevisionCode ( ) {
94208 const cpuInfo = fs_1 . default . readFileSync ( '/proc/cpuinfo' , { encoding : 'utf8' } ) ;
95209 const revisionLine = cpuInfo . split ( '\n' )
0 commit comments