Skip to content

Commit 074afec

Browse files
committed
janky working sharkfin vpd
1 parent e85ae13 commit 074afec

File tree

6 files changed

+77
-9
lines changed

6 files changed

+77
-9
lines changed

Cargo.lock

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/gimlet/base.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ description = "U.2 Sharkfin A VPD"
490490
name = "sharkfin_a_vpd"
491491
refdes = ["J206", "U7"]
492492
removable = true
493+
fruid = "single-barcode"
493494

494495
[[config.i2c.devices]]
495496
bus = "front"
@@ -526,6 +527,7 @@ description = "U.2 Sharkfin B VPD"
526527
name = "sharkfin_b_vpd"
527528
refdes = ["J207", "U7"]
528529
removable = true
530+
fruid = "single-barcode"
529531

530532
[[config.i2c.devices]]
531533
bus = "front"
@@ -562,6 +564,7 @@ description = "U.2 Sharkfin C VPD"
562564
name = "sharkfin_c_vpd"
563565
refdes = ["J208", "U7"]
564566
removable = true
567+
fruid = "single-barcode"
565568

566569
[[config.i2c.devices]]
567570
bus = "front"
@@ -598,6 +601,7 @@ description = "U.2 Sharkfin D VPD"
598601
name = "sharkfin_d_vpd"
599602
refdes = ["J209", "U7"]
600603
removable = true
604+
fruid = "single-barcode"
601605

602606
[[config.i2c.devices]]
603607
bus = "front"
@@ -634,6 +638,7 @@ description = "U.2 Sharkfin E VPD"
634638
name = "sharkfin_e_vpd"
635639
refdes = ["J210", "U7"]
636640
removable = true
641+
fruid = "single-barcode"
637642

638643
[[config.i2c.devices]]
639644
bus = "front"
@@ -670,6 +675,7 @@ description = "U.2 Sharkfin F VPD"
670675
name = "sharkfin_f_vpd"
671676
refdes = ["J211", "U7"]
672677
removable = true
678+
fruid = "single-barcode"
673679

674680
[[config.i2c.devices]]
675681
bus = "front"
@@ -706,6 +712,7 @@ description = "U.2 Sharkfin G VPD"
706712
name = "sharkfin_g_vpd"
707713
refdes = ["J212", "U7"]
708714
removable = true
715+
fruid = "single-barcode"
709716

710717
[[config.i2c.devices]]
711718
bus = "front"
@@ -742,6 +749,7 @@ description = "U.2 Sharkfin H VPD"
742749
name = "sharkfin_h_vpd"
743750
refdes = ["J213", "U7"]
744751
removable = true
752+
fruid = "single-barcode"
745753

746754
[[config.i2c.devices]]
747755
bus = "front"
@@ -778,6 +786,7 @@ description = "U.2 Sharkfin I VPD"
778786
name = "sharkfin_i_vpd"
779787
refdes = ["J214", "U7"]
780788
removable = true
789+
fruid = "single-barcode"
781790

782791
[[config.i2c.devices]]
783792
bus = "front"
@@ -814,6 +823,7 @@ description = "U.2 Sharkfin J VPD"
814823
name = "sharkfin_j_vpd"
815824
refdes = ["J215", "U7"]
816825
removable = true
826+
fruid = "single-barcode"
817827

818828
[[config.i2c.devices]]
819829
bus = "front"
@@ -840,7 +850,7 @@ name = "U2_N9"
840850
refdes = ["J215", "J1"]
841851
removable = true
842852

843-
[[config.i2c.devices]]
853+
[[config.i2c.devices]]faux_mgs
844854
bus = "front"
845855
mux = 3
846856
segment = 4
@@ -849,6 +859,7 @@ device = "at24csw080"
849859
name = "local_vpd"
850860
description = "Gimlet VPD"
851861
refdes = "U615"
862+
fruid = "single-barcode"
852863

853864
#
854865
# M.2 NVMe bus mux. Segments:

build/i2c/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ pub enum Refdes {
233233
}
234234

235235
#[derive(Clone, Debug, Deserialize, PartialOrd, Ord, Eq, PartialEq)]
236+
#[serde(rename_all = "kebab-case")]
236237
pub enum FruidMode {
237238
SingleBarcode,
238239
NestedBarcode,

task/control-plane-agent/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ num-traits.workspace = true
1414
serde.workspace = true
1515
ssmarshal.workspace = true
1616
static_assertions.workspace = true
17+
tlvc.workspace = true
1718
zerocopy.workspace = true
1819
zerocopy-derive.workspace = true
1920

@@ -30,6 +31,7 @@ drv-i2c-devices = { path = "../../drv/i2c-devices" }
3031
drv-ignition-api = { path = "../../drv/ignition-api", optional = true }
3132
drv-lpc55-update-api = { path = "../../drv/lpc55-update-api" }
3233
drv-monorail-api = { path = "../../drv/monorail-api", optional = true }
34+
drv-oxide-vpd = { path = "../../drv/oxide-vpd" }
3335
drv-sidecar-seq-api = { path = "../../drv/sidecar-seq-api", optional = true }
3436
drv-sprot-api = { path = "../../drv/sprot-api" }
3537
drv-stm32h7-update-api = { path = "../../drv/stm32h7-update-api" }
@@ -42,6 +44,7 @@ dump-agent-api = { path = "../dump-agent-api" }
4244
task-vpd-api = { path = "../../task/vpd-api", optional = true }
4345
host-sp-messages = { path = "../../lib/host-sp-messages" }
4446
lpc55-rom-data = { path = "../../lib/lpc55-rom-data" }
47+
oxide-barcode = { path = "../../lib/oxide-barcode" }
4548
ringbuf = { path = "../../lib/ringbuf" }
4649
counters = { path = "../../lib/counters" }
4750
task-control-plane-agent-api = { path = "../control-plane-agent-api" }

task/control-plane-agent/src/inventory.rs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5+
use drv_i2c_api::{self as i2c, I2cDevice};
56
use drv_i2c_devices::at24csw080::At24Csw080;
67
use gateway_messages::measurement::{
78
Measurement, MeasurementError, MeasurementKind,
89
};
910
use gateway_messages::sp_impl::{BoundsChecked, DeviceDescription};
11+
use gateway_messages::vpd::{OxideVpd, Vpd};
1012
use gateway_messages::{
1113
ComponentDetails, DeviceCapabilities, DevicePresence, SpComponent, SpError,
14+
VpdError,
1215
};
1316
use task_sensor_api::Sensor as SensorTask;
1417
use task_sensor_api::SensorError;
@@ -88,7 +91,7 @@ impl Inventory {
8891
let nfruid = match dev.fruid {
8992
Some(FruidMode::At24Csw080Barcode(_)) => 1,
9093
Some(FruidMode::At24Csw080Nested(_)) => 0, // TODO(eliza): implement nested SASY barcodes
91-
Some(FruidMode::Tmp117(_)) => 1,
94+
Some(FruidMode::Tmp117(_)) => 0, // TODO(eliza): implement tmp117 fruid
9295
None => 0,
9396
};
9497
Ok(nsensors + nfruid)
@@ -138,7 +141,18 @@ impl Inventory {
138141
match fruid {
139142
FruidMode::At24Csw080Barcode(f) => {
140143
let dev = f(I2C.get_task_id());
141-
todo!()
144+
match read_one_barcode(dev, &[(*b"BARC", 0)]) {
145+
Ok(oxide_barcode::VpdIdentity {
146+
revision,
147+
serial,
148+
part_number,
149+
}) => ComponentDetails::Vpd(Vpd::Oxide(OxideVpd {
150+
rev: revision,
151+
serial,
152+
part_number,
153+
})),
154+
Err(err) => panic!(), // TODO(eliza): figure out this
155+
}
142156
}
143157
FruidMode::At24Csw080Nested(_) => todo!(),
144158
FruidMode::Tmp117(_) => todo!(),
@@ -179,6 +193,9 @@ impl Inventory {
179193
if !device.sensors.is_empty() {
180194
capabilities |= DeviceCapabilities::HAS_MEASUREMENT_CHANNELS;
181195
}
196+
if device.fruid.is_some() {
197+
capabilities |= DeviceCapabilities::HAS_VPD;
198+
}
182199
DeviceDescription {
183200
component: SpComponent { id: device.id },
184201
device: device.device,
@@ -245,6 +262,42 @@ impl TryFrom<&'_ SpComponent> for Index {
245262
}
246263
}
247264

265+
/// Free function to read a nested barcode, translating errors appropriately
266+
fn read_one_barcode(
267+
dev: I2cDevice,
268+
path: &[([u8; 4], usize)],
269+
) -> Result<oxide_barcode::VpdIdentity, VpdError> {
270+
let eeprom = At24Csw080::new(dev);
271+
let mut barcode = [0; 32];
272+
match drv_oxide_vpd::read_config_nested_from_into(
273+
eeprom,
274+
path,
275+
&mut barcode,
276+
) {
277+
Ok(n) => {
278+
// extract barcode!
279+
let identity = oxide_barcode::VpdIdentity::parse(&barcode[..n])
280+
.map_err(|_| VpdError::DeviceError)?;
281+
Ok(identity)
282+
}
283+
Err(
284+
drv_oxide_vpd::VpdError::ErrorOnBegin(err)
285+
| drv_oxide_vpd::VpdError::ErrorOnRead(err)
286+
| drv_oxide_vpd::VpdError::ErrorOnNext(err)
287+
| drv_oxide_vpd::VpdError::InvalidChecksum(err),
288+
) if err
289+
== tlvc::TlvcReadError::User(
290+
drv_i2c_devices::at24csw080::Error::I2cError(
291+
i2c::ResponseCode::NoDevice,
292+
),
293+
) =>
294+
{
295+
Err(VpdError::NotPresent)
296+
}
297+
Err(..) => Err(VpdError::DeviceError),
298+
}
299+
}
300+
248301
use devices_with_static_validation::OUR_DEVICES;
249302
// We tag this with module `#[allow(dead_code)]` to prevent warnings about the
250303
// contents of this module not being used; it contains constants used in static

task/validate-api/build.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,10 @@ fn write_pub_device_descriptions() -> anyhow::Result<()> {
127127
&dev.device,
128128
id.to_lower_ident()
129129
);
130-
writeln!(
131-
file,
132-
" fruid: Some({mode}({devname})),"
133-
)?;
130+
writeln!(file, " fruid: Some({mode}({devname})),")?;
134131
}
135132
(None, _) => {
136-
writeln!(file, " fruid: None,")?;
133+
writeln!(file, " fruid: None,")?;
137134
}
138135
(Some(mode), None) => {
139136
println!(

0 commit comments

Comments
 (0)