15
15
// with this program; if not, write to the Free Software Foundation, Inc.,
16
16
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
18
+ use anyhow:: { bail, Result } ;
18
19
use async_std:: sync:: Arc ;
19
20
use nix:: sys:: utsname:: uname;
20
21
use serde:: { Deserialize , Serialize } ;
@@ -24,6 +25,10 @@ use crate::broker::{BrokerBuilder, Topic};
24
25
#[ cfg( feature = "demo_mode" ) ]
25
26
mod read_dt_props {
26
27
const DEMO_DATA_STR : & [ ( & str , & str ) ] = & [
28
+ (
29
+ "compatible" ,
30
+ "lxa,stm32mp153c-tac-gen3\0 oct,stm32mp15xx-osd32\0 st,stm32mp153" ,
31
+ ) ,
27
32
( "chosen/barebox-version" , "barebox-2022.11.0-20221121-1" ) ,
28
33
(
29
34
"chosen/baseboard-factory-data/pcba-hardware-release" ,
@@ -141,23 +146,53 @@ impl Barebox {
141
146
}
142
147
}
143
148
149
+ #[ derive( Clone , Copy , Serialize , Deserialize ) ]
150
+ pub enum HardwareGeneration {
151
+ Gen1 ,
152
+ Gen2 ,
153
+ Gen3 ,
154
+ }
155
+
156
+ impl HardwareGeneration {
157
+ pub fn get ( ) -> Result < Self > {
158
+ let compatible = read_dt_property ( "compatible" ) ;
159
+
160
+ // The compatible property consists of strings separated by NUL bytes.
161
+ // We are interested in the first of these strings.
162
+ let device = compatible. split ( '\0' ) . next ( ) . unwrap_or ( "<empty>" ) ;
163
+
164
+ match device {
165
+ "lxa,stm32mp157c-tac-gen1" => Ok ( Self :: Gen1 ) ,
166
+ "lxa,stm32mp157c-tac-gen2" => Ok ( Self :: Gen2 ) ,
167
+ "lxa,stm32mp153c-tac-gen3" => Ok ( Self :: Gen3 ) ,
168
+ gen => bail ! ( "Running on unknown LXA TAC hardware generation \" {gen}\" " ) ,
169
+ }
170
+ }
171
+ }
172
+
144
173
pub struct System {
145
174
#[ allow( dead_code) ]
146
175
pub uname : Arc < Topic < Arc < Uname > > > ,
147
176
#[ allow( dead_code) ]
148
177
pub barebox : Arc < Topic < Arc < Barebox > > > ,
149
178
#[ allow( dead_code) ]
150
179
pub tacd_version : Arc < Topic < String > > ,
180
+ #[ allow( dead_code) ]
181
+ pub hardware_generation : Arc < Topic < HardwareGeneration > > ,
151
182
}
152
183
153
184
impl System {
154
- pub fn new ( bb : & mut BrokerBuilder ) -> Self {
185
+ pub fn new ( bb : & mut BrokerBuilder , hardware_generation : HardwareGeneration ) -> Self {
155
186
let version = env ! ( "VERSION_STRING" ) . to_string ( ) ;
156
187
157
188
Self {
158
189
uname : bb. topic_ro ( "/v1/tac/info/uname" , Some ( Arc :: new ( Uname :: get ( ) ) ) ) ,
159
190
barebox : bb. topic_ro ( "/v1/tac/info/bootloader" , Some ( Arc :: new ( Barebox :: get ( ) ) ) ) ,
160
191
tacd_version : bb. topic_ro ( "/v1/tac/info/tacd/version" , Some ( version) ) ,
192
+ hardware_generation : bb. topic_ro (
193
+ "/v1/tac/info/hardware_generation" ,
194
+ Some ( hardware_generation) ,
195
+ ) ,
161
196
}
162
197
}
163
198
}
0 commit comments