From b200c9f415753782cfacb43fc93d13f097916112 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 29 Jan 2025 15:09:21 +0800 Subject: [PATCH 1/2] framework_lib: Add support for getting EC features framework_tool --features Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/command.rs | 2 + framework_lib/src/chromium_ec/commands.rs | 140 ++++++++++++++++++++++ framework_lib/src/chromium_ec/mod.rs | 17 +++ framework_lib/src/commandline/clap_std.rs | 5 + framework_lib/src/commandline/mod.rs | 4 + framework_lib/src/commandline/uefi.rs | 4 + 6 files changed, 172 insertions(+) diff --git a/framework_lib/src/chromium_ec/command.rs b/framework_lib/src/chromium_ec/command.rs index c8236786..6c397870 100644 --- a/framework_lib/src/chromium_ec/command.rs +++ b/framework_lib/src/chromium_ec/command.rs @@ -34,6 +34,8 @@ pub enum EcCommands { I2cPassthrough = 0x9e, ConsoleSnapshot = 0x97, ConsoleRead = 0x98, + /// List the features supported by the firmware + GetFeatures = 0x0D, /// Force reboot, causes host reboot as well Reboot = 0xD1, /// Control EC boot diff --git a/framework_lib/src/chromium_ec/commands.rs b/framework_lib/src/chromium_ec/commands.rs index 5a1add13..8a31476d 100644 --- a/framework_lib/src/chromium_ec/commands.rs +++ b/framework_lib/src/chromium_ec/commands.rs @@ -233,6 +233,146 @@ impl EcRequest<()> for EcRequestConsoleRead { } } +/// Supported features +#[derive(Debug, FromPrimitive)] +pub enum EcFeatureCode { + /// This image contains a limited set of features. Another image + /// in RW partition may support more features. + Limited = 0, + /// Commands for probing/reading/writing/erasing the flash in the + /// EC are present. + Flash = 1, + /// Can control the fan speed directly. + PwmFan = 2, + /// Can control the intensity of the keyboard backlight. + PwmKeyboardBacklight = 3, + /// Support Google lightbar, introduced on Pixel. + Lightbar = 4, + /// Control of LEDs + Led = 5, + /// Exposes an interface to control gyro and sensors. + /// The host goes through the EC to access these sensors. + /// In addition, the EC may provide composite sensors, like lid angle. + MotionSense = 6, + /// The keyboard is controlled by the EC + Keyboard = 7, + /// The AP can use part of the EC flash as persistent storage. + PersistentStorage = 8, + /// The EC monitors BIOS port 80h, and can return POST codes. + Port80 = 9, + /// Thermal management: include TMP specific commands. + /// Higher level than direct fan control. + Thermal = 10, + /// Can switch the screen backlight on/off + BacklightSwitch = 11, + /// Can switch the wifi module on/off + WifiSwitch = 12, + /// Monitor host events, through for example SMI or SCI + HostEvents = 13, + /// The EC exposes GPIO commands to control/monitor connected devices. + Gpio = 14, + /// The EC can send i2c messages to downstream devices. + I2c = 15, + /// Command to control charger are included + Charger = 16, + /// Simple battery support. + Battery = 17, + /// Support Smart battery protocol + /// (Common Smart Battery System Interface Specification) + SmartBattery = 18, + /// EC can detect when the host hangs. + HangDetect = 19, + /// Report power information, for pit only + Pmu = 20, + /// Another Cros EC device is present downstream of this one + SubMcu = 21, + /// Support USB Power delivery (PD) commands + UsbPd = 22, + /// Control USB multiplexer, for audio through USB port for instance. + UsbMux = 23, + /// Motion Sensor code has an internal software FIFO + MotionSenseFifo = 24, + /// Support temporary secure vstore + SecureVstore = 25, + /// EC decides on USB-C SS mux state, muxes configured by host + UsbcSsMuxVirtual = 26, + /// EC has RTC feature that can be controlled by host commands + Rtc = 27, + /// The MCU exposes a Fingerprint sensor + Fingerprint = 28, + /// The MCU exposes a Touchpad + Touchpad = 29, + /// The MCU has RWSIG task enabled + RwSig = 30, + /// EC has device events support + DeviceEvent = 31, + /// EC supports the unified wake masks for LPC/eSPI systems + UnifiedWakeMasks = 32, + /// EC supports 64-bit host events + HostEvent64 = 33, + /// EC runs code in RAM (not in place, a.k.a. XIP) + ExecInRam = 34, + /// EC supports CEC commands + Cec = 35, + /// EC supports tight sensor timestamping. + MotionSenseTightTimesStamps = 36, + /// + /// EC supports tablet mode detection aligned to Chrome and allows + /// setting of threshold by host command using + /// MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. + RefinedTabletModeHysteresis = 37, + /// Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2. + /// Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should + /// be sent to RO to be precise. + Efs2 = 38, + /// The MCU is a System Companion Processor (SCP). + Scp = 39, + /// The MCU is an Integrated Sensor Hub + Ish = 40, + /// New TCPMv2 TYPEC_ prefaced commands supported + TypecCmd = 41, + /// The EC will wait for direction from the AP to enter Type-C alternate + /// modes or USB4. + TypecRequireApModeEntry = 42, + /// The EC will wait for an acknowledge from the AP after setting the + /// mux. + TypeCMuxRequireApAck = 43, + /// The EC supports entering and residing in S4. + S4Residency = 44, + /// The EC supports the AP directing mux sets for the board. + TypeCApMuxSet = 45, + /// The EC supports the AP composing VDMs for us to send. + TypeCApVdmSend = 46, + /// The EC supports system safe mode panic recovery. + SystemSafeMode = 47, + /// The EC will reboot on runtime assertion failures. + AssertReboots = 48, + /// The EC image is built with tokenized logging enabled. + TokenizedLogging = 49, + /// The EC supports triggering an STB dump. + AmdStbDump = 50, + /// The EC supports memory dump commands. + MemoryDump = 51, + /// The EC supports DP2.1 capability + Dp21 = 52, + /// The MCU is System Companion Processor Core 1 + ScpC1 = 53, + /// The EC supports UCSI PPM. + UcsiPpm = 54, +} + +pub struct EcRequestGetFeatures {} + +pub struct EcResponseGetFeatures { + pub flags: [u32; 2], +} + +impl EcRequest for EcRequestGetFeatures { + fn command_id() -> EcCommands { + EcCommands::GetFeatures + } +} + #[repr(u8)] pub enum RebootEcCmd { /// Cancel a pending reboot diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index 570e2ebd..a64102bf 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -807,6 +807,23 @@ impl CrosEc { Ok(ascii) } + /// Check features supported by the firmware + pub fn get_features(&self) -> EcResult<()> { + let data = EcRequestGetFeatures {}.send_command(self)?; + for i in 0..64 { + let byte = i / 32; + let bit = i % 32; + let val = (data.flags[byte] & (1 << bit)) > 0; + let feat: Option = FromPrimitive::from_usize(i); + + if let Some(feat) = feat { + println!("{:>2}: {:>5} {:?}", i, val, feat); + } + } + + Ok(()) + } + /// Instantly reboot EC and host pub fn reboot(&self) -> EcResult<()> { EcRequestReboot {}.send_command(self) diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index 92dd77c2..30e54d2e 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -23,6 +23,10 @@ struct ClapCli { #[arg(long)] version: bool, + /// Show features support by the firmware + #[arg(long)] + features: bool, + /// Display the UEFI ESRT table #[arg(long)] esrt: bool, @@ -212,6 +216,7 @@ pub fn parse(args: &[String]) -> Cli { verbosity: args.verbosity.log_level_filter(), versions: args.versions, version: args.version, + features: args.features, esrt: args.esrt, device: args.device, compare_version: args.compare_version, diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 8266eea7..2f3e021b 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -121,6 +121,7 @@ pub struct Cli { pub verbosity: log::LevelFilter, pub versions: bool, pub version: bool, + pub features: bool, pub esrt: bool, pub device: Option, pub compare_version: Option, @@ -679,6 +680,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { print_versions(&ec); } else if args.version { print_tool_version(); + } else if args.features { + ec.get_features().unwrap(); } else if args.esrt { print_esrt(); } else if let Some(compare_version_ver) = &args.compare_version { @@ -963,6 +966,7 @@ Options: -q, --quiet... Less output per occurrence --versions List current firmware versions --version Show tool version information (Add -vv for more detailed information) + --features Show features support by the firmware --esrt Display the UEFI ESRT table --device Device used to compare firmware version [possible values: bios, ec, pd0, pd1, rtm01, rtm23] --compare-version Version string used to match firmware version (use with --device) diff --git a/framework_lib/src/commandline/uefi.rs b/framework_lib/src/commandline/uefi.rs index 3a656fe6..c6232f75 100644 --- a/framework_lib/src/commandline/uefi.rs +++ b/framework_lib/src/commandline/uefi.rs @@ -57,6 +57,7 @@ pub fn parse(args: &[String]) -> Cli { paginate: false, versions: false, version: false, + features: false, esrt: false, device: None, compare_version: None, @@ -123,6 +124,9 @@ pub fn parse(args: &[String]) -> Cli { } else if arg == "--version" { cli.version = true; found_an_option = true; + } else if arg == "--features" { + cli.features = true; + found_an_option = true; } else if arg == "-b" { cli.paginate = true; found_an_option = true; From 582baf213d70147671883012a0832101d09b4961 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 29 Jan 2025 15:10:06 +0800 Subject: [PATCH 2/2] trivial: Turn some comments into doc comments Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/commands.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/framework_lib/src/chromium_ec/commands.rs b/framework_lib/src/chromium_ec/commands.rs index 8a31476d..9a7f784b 100644 --- a/framework_lib/src/chromium_ec/commands.rs +++ b/framework_lib/src/chromium_ec/commands.rs @@ -412,7 +412,8 @@ pub enum RebootEcFlags { } pub struct EcRequestRebootEc { - pub cmd: u8, /* enum RebootEcCmd */ + /// See enum RebootEcCmd + pub cmd: u8, pub flags: u8, } @@ -770,10 +771,8 @@ impl EcRequest for EcRequestChargeLimitControl { } } -/* - * Configure the behavior of the charge limit control. - * TODO: Use this - */ +/// Configure the behavior of the charge limit control. +/// TODO: Use this pub const EC_CHARGE_LIMIT_RESTORE: u8 = 0x7F; #[repr(u8)]