Skip to content

Commit 3243cb7

Browse files
committed
compare-version: Use correct PD version
Make sure it's the active one, and use base version on TGL. Signed-off-by: Daniel Schaefer <[email protected]>
1 parent f65f1dc commit 3243cb7

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

framework_lib/src/ccgx/mod.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
//! Interact with Infineon (formerly Cypress) PD controllers (their firmware binaries) in the CCGx series
22
3+
use alloc::string::String;
4+
use alloc::string::ToString;
35
#[cfg(feature = "uefi")]
46
use core::prelude::rust_2021::derive;
57
use num_derive::FromPrimitive;
68
use std::fmt;
79

810
use crate::chromium_ec::{CrosEc, EcResult};
11+
use crate::smbios;
12+
use crate::util::Platform;
913

1014
use self::device::{FwMode, PdController, PdPort};
1115

@@ -102,7 +106,7 @@ pub enum SiliconId {
102106
Ccg8 = 0x3580,
103107
}
104108

105-
#[derive(Debug, PartialEq)]
109+
#[derive(Debug, PartialEq, Copy, Clone)]
106110
pub struct BaseVersion {
107111
/// Major part of the version. X of X.Y.Z.BB
108112
pub major: u8,
@@ -138,15 +142,15 @@ impl From<u32> for BaseVersion {
138142
}
139143
}
140144

141-
#[derive(Debug, PartialEq)]
145+
#[derive(Debug, PartialEq, Copy, Clone)]
142146
pub enum Application {
143147
Notebook,
144148
Monitor,
145149
AA,
146150
Invalid,
147151
}
148152

149-
#[derive(Debug, PartialEq)]
153+
#[derive(Debug, PartialEq, Copy, Clone)]
150154
pub struct AppVersion {
151155
pub application: Application,
152156
/// Major part of the version. X of X.Y.Z
@@ -185,7 +189,7 @@ impl From<u32> for AppVersion {
185189
}
186190
}
187191

188-
#[derive(Debug, PartialEq)]
192+
#[derive(Debug, PartialEq, Copy, Clone)]
189193
pub struct ControllerVersion {
190194
pub base: BaseVersion,
191195
pub app: AppVersion,
@@ -199,6 +203,26 @@ pub struct ControllerFirmwares {
199203
pub main_fw: ControllerVersion,
200204
}
201205

206+
impl ControllerFirmwares {
207+
pub fn active_fw(&self) -> ControllerVersion {
208+
match self.active_fw {
209+
FwMode::MainFw => self.main_fw,
210+
FwMode::BackupFw => self.backup_fw,
211+
FwMode::BootLoader => self.bootloader,
212+
}
213+
}
214+
215+
pub fn active_fw_ver(&self) -> String {
216+
let active = self.active_fw();
217+
// On 11th Gen we modified base version instead of app version
218+
if let Some(Platform::IntelGen11) = smbios::get_platform() {
219+
active.base.to_string()
220+
} else {
221+
active.app.to_string()
222+
}
223+
}
224+
}
225+
202226
#[derive(Debug, PartialEq)]
203227
pub struct PdVersions {
204228
pub controller01: ControllerFirmwares,

framework_lib/src/commandline/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ fn compare_version(device: Option<HardwareDeviceType>, version: String, ec: &Cro
537537
}
538538
if device == Some(HardwareDeviceType::PD0) {
539539
if let Ok(pd_versions) = ccgx::get_pd_controller_versions(ec) {
540-
let ver = pd_versions.controller01.main_fw.app.to_string();
540+
let ver = pd_versions.controller01.active_fw_ver();
541541
println!("Comparing PD0 version {:?}", ver);
542542

543543
if ver.contains(&version) {
@@ -549,7 +549,7 @@ fn compare_version(device: Option<HardwareDeviceType>, version: String, ec: &Cro
549549
}
550550
if device == Some(HardwareDeviceType::PD1) {
551551
if let Ok(pd_versions) = ccgx::get_pd_controller_versions(ec) {
552-
let ver = pd_versions.controller23.main_fw.app.to_string();
552+
let ver = pd_versions.controller23.active_fw_ver();
553553
println!("Comparing PD1 version {:?}", ver);
554554

555555
if ver.contains(&version) {

0 commit comments

Comments
 (0)