Skip to content

Commit

Permalink
tgl: Fix PD controller version
Browse files Browse the repository at this point in the history
On TGL we modified the base version, not the app version.
`-version` would show the incorrect version.
`--pd-info` shows both.

```
FS1:\> framework_tool.efi --versions
UEFI BIOS
  Version:        03.19
  Release Date:   05/29/2023
EC Firmware
  Build version:  "hx20_v0.0.1-f6d6b92 2023-05-26 00:03:59 runner@fv-az504-734"
  RO Version:     "hx20_v0.0.1-f6d6b92"
  RW Version:     "hx20_v0.0.1-f6d6b92"
  Current image:  RO
PD Controllers
  Right (01)
    Main:       3.4.0.2575 (Active)
    Backup:     3.4.0.2575
  Left  (23)
    Main:       3.4.0.2575 (Active)
    Backup:     3.4.0.2575
Retimers
  Left:           0xCF (207)
  Right:          0xCF (207)
```

Signed-off-by: Daniel Schaefer <[email protected]>
  • Loading branch information
JohnAZoidberg committed Aug 9, 2024
1 parent 2e30627 commit de8e059
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 25 deletions.
2 changes: 2 additions & 0 deletions framework_lib/src/ccgx/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ impl PdController {
Ok((fw_mode, flash_row_size))
}
pub fn get_fw_versions(&self) -> EcResult<ControllerFirmwares> {
let (active_fw, _row_size) = self.get_device_info()?;
Ok(ControllerFirmwares {
active_fw,
bootloader: self.get_single_fw_ver(FwMode::BootLoader)?,
backup_fw: self.get_single_fw_ver(FwMode::BackupFw)?,
main_fw: self.get_single_fw_ver(FwMode::MainFw)?,
Expand Down
9 changes: 3 additions & 6 deletions framework_lib/src/ccgx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fmt;

use crate::chromium_ec::{CrosEc, EcResult};

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

pub mod binary;
pub mod device;
Expand Down Expand Up @@ -159,11 +159,7 @@ pub struct AppVersion {

impl fmt::Display for AppVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}.{}.{:0>2} ({:?})",
self.major, self.minor, self.circuit, self.application
)
write!(f, "{}.{}.{:0>2}", self.major, self.minor, self.circuit)
}
}

Expand Down Expand Up @@ -197,6 +193,7 @@ pub struct ControllerVersion {

#[derive(Debug, PartialEq)]
pub struct ControllerFirmwares {
pub active_fw: FwMode,
pub bootloader: ControllerVersion,
pub backup_fw: ControllerVersion,
pub main_fw: ControllerVersion,
Expand Down
80 changes: 61 additions & 19 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::capsule;
use crate::capsule_content::{
find_bios_version, find_ec_in_bios_cap, find_pd_in_bios_cap, find_retimer_version,
};
use crate::ccgx::device::{PdController, PdPort};
use crate::ccgx::device::{FwMode, PdController, PdPort};
#[cfg(feature = "hidapi")]
use crate::ccgx::hid::{check_ccg_fw_version, find_devices, DP_CARD_PID, HDMI_CARD_PID};
use crate::ccgx::{self, SiliconId::*};
Expand All @@ -47,7 +47,7 @@ use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
#[cfg(feature = "uefi")]
use crate::uefi::enable_page_break;
use crate::util;
use crate::util::Config;
use crate::util::{Config, Platform};
#[cfg(feature = "hidapi")]
use hidapi::HidApi;
use sha2::{Digest, Sha256, Sha384, Sha512};
Expand Down Expand Up @@ -289,6 +289,14 @@ fn flash_dp_hdmi_card(pd_bin_path: &str) {
}
}

fn active_mode(mode: &FwMode, reference: FwMode) -> &'static str {
if mode == &reference {
" (Active)"
} else {
""
}
}

fn print_versions(ec: &CrosEc) {
println!("UEFI BIOS");
if let Some(smbios) = get_smbios() {
Expand Down Expand Up @@ -322,24 +330,57 @@ fn print_versions(ec: &CrosEc) {
println!("PD Controllers");

if let Ok(pd_versions) = ccgx::get_pd_controller_versions(ec) {
let right = &pd_versions.controller01;
let left = &pd_versions.controller23;
println!(" Right (01)");
println!(
" Main App: {}",
pd_versions.controller01.main_fw.app
);
println!(
" Backup App: {}",
pd_versions.controller01.backup_fw.app
);
// let active_mode =
if let Some(Platform::IntelGen11) = smbios::get_platform() {
println!(
" Main: {}{}",
right.main_fw.base,
active_mode(&right.active_fw, FwMode::MainFw)
);
println!(
" Backup: {}{}",
right.backup_fw.base,
active_mode(&right.active_fw, FwMode::BackupFw)
);
} else {
println!(
" Main: {}{}",
right.main_fw.app,
active_mode(&right.active_fw, FwMode::MainFw)
);
println!(
" Backup: {}{}",
right.backup_fw.app,
active_mode(&right.active_fw, FwMode::BackupFw)
);
}
println!(" Left (23)");
println!(
" Main App: {}",
pd_versions.controller23.main_fw.app
);
println!(
" Backup App: {}",
pd_versions.controller23.backup_fw.app
);
if let Some(Platform::IntelGen11) = smbios::get_platform() {
println!(
" Main: {}{}",
left.main_fw.base,
active_mode(&left.active_fw, FwMode::MainFw)
);
println!(
" Backup: {}{}",
left.backup_fw.base,
active_mode(&left.active_fw, FwMode::BackupFw)
);
} else {
println!(
" Main: {}{}",
left.main_fw.app,
active_mode(&left.active_fw, FwMode::MainFw)
);
println!(
" Backup: {}{}",
left.backup_fw.app,
active_mode(&left.active_fw, FwMode::BackupFw)
);
}
} else if let Ok(pd_versions) = power::read_pd_version(ec) {
// As fallback try to get it from the EC. But not all EC versions have this command
println!(" Right (01): {}", pd_versions.controller01.app);
Expand Down Expand Up @@ -486,7 +527,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {

// Must be run before any application code to set the config
if args.pd_addrs.is_some() && args.pd_ports.is_some() && args.has_mec.is_some() {
let platform = util::Platform::GenericFramework(
let platform = Platform::GenericFramework(
args.pd_addrs.unwrap(),
args.pd_ports.unwrap(),
args.has_mec.unwrap(),
Expand Down Expand Up @@ -898,6 +939,7 @@ fn selftest(ec: &CrosEc) -> Option<()> {
println!(" Getting AC info from EC");
// All our laptops have at least 4 PD ports so far
if power::get_pd_info(ec, 4).iter().any(|x| x.is_err()) {
println!(" Failed to get PD Info from EC");
return None;
}

Expand Down
1 change: 1 addition & 0 deletions framework_lib/src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ fn parse_pd_ver(data: &[u8; 8]) -> ControllerVersion {
}

// NOTE: Only works on ADL at the moment!
// TODO: Not on TGL, need to check if RPL and later have it.
pub fn read_pd_version(ec: &CrosEc) -> EcResult<MainPdVersions> {
let info = EcRequestReadPdVersion {}.send_command(ec)?;

Expand Down

0 comments on commit de8e059

Please sign in to comment.