Skip to content

Commit b200c9f

Browse files
committed
framework_lib: Add support for getting EC features
framework_tool --features Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent fb43228 commit b200c9f

File tree

6 files changed

+172
-0
lines changed

6 files changed

+172
-0
lines changed

framework_lib/src/chromium_ec/command.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub enum EcCommands {
3434
I2cPassthrough = 0x9e,
3535
ConsoleSnapshot = 0x97,
3636
ConsoleRead = 0x98,
37+
/// List the features supported by the firmware
38+
GetFeatures = 0x0D,
3739
/// Force reboot, causes host reboot as well
3840
Reboot = 0xD1,
3941
/// Control EC boot

framework_lib/src/chromium_ec/commands.rs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,146 @@ impl EcRequest<()> for EcRequestConsoleRead {
233233
}
234234
}
235235

236+
/// Supported features
237+
#[derive(Debug, FromPrimitive)]
238+
pub enum EcFeatureCode {
239+
/// This image contains a limited set of features. Another image
240+
/// in RW partition may support more features.
241+
Limited = 0,
242+
/// Commands for probing/reading/writing/erasing the flash in the
243+
/// EC are present.
244+
Flash = 1,
245+
/// Can control the fan speed directly.
246+
PwmFan = 2,
247+
/// Can control the intensity of the keyboard backlight.
248+
PwmKeyboardBacklight = 3,
249+
/// Support Google lightbar, introduced on Pixel.
250+
Lightbar = 4,
251+
/// Control of LEDs
252+
Led = 5,
253+
/// Exposes an interface to control gyro and sensors.
254+
/// The host goes through the EC to access these sensors.
255+
/// In addition, the EC may provide composite sensors, like lid angle.
256+
MotionSense = 6,
257+
/// The keyboard is controlled by the EC
258+
Keyboard = 7,
259+
/// The AP can use part of the EC flash as persistent storage.
260+
PersistentStorage = 8,
261+
/// The EC monitors BIOS port 80h, and can return POST codes.
262+
Port80 = 9,
263+
/// Thermal management: include TMP specific commands.
264+
/// Higher level than direct fan control.
265+
Thermal = 10,
266+
/// Can switch the screen backlight on/off
267+
BacklightSwitch = 11,
268+
/// Can switch the wifi module on/off
269+
WifiSwitch = 12,
270+
/// Monitor host events, through for example SMI or SCI
271+
HostEvents = 13,
272+
/// The EC exposes GPIO commands to control/monitor connected devices.
273+
Gpio = 14,
274+
/// The EC can send i2c messages to downstream devices.
275+
I2c = 15,
276+
/// Command to control charger are included
277+
Charger = 16,
278+
/// Simple battery support.
279+
Battery = 17,
280+
/// Support Smart battery protocol
281+
/// (Common Smart Battery System Interface Specification)
282+
SmartBattery = 18,
283+
/// EC can detect when the host hangs.
284+
HangDetect = 19,
285+
/// Report power information, for pit only
286+
Pmu = 20,
287+
/// Another Cros EC device is present downstream of this one
288+
SubMcu = 21,
289+
/// Support USB Power delivery (PD) commands
290+
UsbPd = 22,
291+
/// Control USB multiplexer, for audio through USB port for instance.
292+
UsbMux = 23,
293+
/// Motion Sensor code has an internal software FIFO
294+
MotionSenseFifo = 24,
295+
/// Support temporary secure vstore
296+
SecureVstore = 25,
297+
/// EC decides on USB-C SS mux state, muxes configured by host
298+
UsbcSsMuxVirtual = 26,
299+
/// EC has RTC feature that can be controlled by host commands
300+
Rtc = 27,
301+
/// The MCU exposes a Fingerprint sensor
302+
Fingerprint = 28,
303+
/// The MCU exposes a Touchpad
304+
Touchpad = 29,
305+
/// The MCU has RWSIG task enabled
306+
RwSig = 30,
307+
/// EC has device events support
308+
DeviceEvent = 31,
309+
/// EC supports the unified wake masks for LPC/eSPI systems
310+
UnifiedWakeMasks = 32,
311+
/// EC supports 64-bit host events
312+
HostEvent64 = 33,
313+
/// EC runs code in RAM (not in place, a.k.a. XIP)
314+
ExecInRam = 34,
315+
/// EC supports CEC commands
316+
Cec = 35,
317+
/// EC supports tight sensor timestamping.
318+
MotionSenseTightTimesStamps = 36,
319+
///
320+
/// EC supports tablet mode detection aligned to Chrome and allows
321+
/// setting of threshold by host command using
322+
/// MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
323+
RefinedTabletModeHysteresis = 37,
324+
/// Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
325+
/// Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
326+
/// be sent to RO to be precise.
327+
Efs2 = 38,
328+
/// The MCU is a System Companion Processor (SCP).
329+
Scp = 39,
330+
/// The MCU is an Integrated Sensor Hub
331+
Ish = 40,
332+
/// New TCPMv2 TYPEC_ prefaced commands supported
333+
TypecCmd = 41,
334+
/// The EC will wait for direction from the AP to enter Type-C alternate
335+
/// modes or USB4.
336+
TypecRequireApModeEntry = 42,
337+
/// The EC will wait for an acknowledge from the AP after setting the
338+
/// mux.
339+
TypeCMuxRequireApAck = 43,
340+
/// The EC supports entering and residing in S4.
341+
S4Residency = 44,
342+
/// The EC supports the AP directing mux sets for the board.
343+
TypeCApMuxSet = 45,
344+
/// The EC supports the AP composing VDMs for us to send.
345+
TypeCApVdmSend = 46,
346+
/// The EC supports system safe mode panic recovery.
347+
SystemSafeMode = 47,
348+
/// The EC will reboot on runtime assertion failures.
349+
AssertReboots = 48,
350+
/// The EC image is built with tokenized logging enabled.
351+
TokenizedLogging = 49,
352+
/// The EC supports triggering an STB dump.
353+
AmdStbDump = 50,
354+
/// The EC supports memory dump commands.
355+
MemoryDump = 51,
356+
/// The EC supports DP2.1 capability
357+
Dp21 = 52,
358+
/// The MCU is System Companion Processor Core 1
359+
ScpC1 = 53,
360+
/// The EC supports UCSI PPM.
361+
UcsiPpm = 54,
362+
}
363+
364+
pub struct EcRequestGetFeatures {}
365+
366+
pub struct EcResponseGetFeatures {
367+
pub flags: [u32; 2],
368+
}
369+
370+
impl EcRequest<EcResponseGetFeatures> for EcRequestGetFeatures {
371+
fn command_id() -> EcCommands {
372+
EcCommands::GetFeatures
373+
}
374+
}
375+
236376
#[repr(u8)]
237377
pub enum RebootEcCmd {
238378
/// Cancel a pending reboot

framework_lib/src/chromium_ec/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,23 @@ impl CrosEc {
807807
Ok(ascii)
808808
}
809809

810+
/// Check features supported by the firmware
811+
pub fn get_features(&self) -> EcResult<()> {
812+
let data = EcRequestGetFeatures {}.send_command(self)?;
813+
for i in 0..64 {
814+
let byte = i / 32;
815+
let bit = i % 32;
816+
let val = (data.flags[byte] & (1 << bit)) > 0;
817+
let feat: Option<EcFeatureCode> = FromPrimitive::from_usize(i);
818+
819+
if let Some(feat) = feat {
820+
println!("{:>2}: {:>5} {:?}", i, val, feat);
821+
}
822+
}
823+
824+
Ok(())
825+
}
826+
810827
/// Instantly reboot EC and host
811828
pub fn reboot(&self) -> EcResult<()> {
812829
EcRequestReboot {}.send_command(self)

framework_lib/src/commandline/clap_std.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ struct ClapCli {
2323
#[arg(long)]
2424
version: bool,
2525

26+
/// Show features support by the firmware
27+
#[arg(long)]
28+
features: bool,
29+
2630
/// Display the UEFI ESRT table
2731
#[arg(long)]
2832
esrt: bool,
@@ -212,6 +216,7 @@ pub fn parse(args: &[String]) -> Cli {
212216
verbosity: args.verbosity.log_level_filter(),
213217
versions: args.versions,
214218
version: args.version,
219+
features: args.features,
215220
esrt: args.esrt,
216221
device: args.device,
217222
compare_version: args.compare_version,

framework_lib/src/commandline/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ pub struct Cli {
121121
pub verbosity: log::LevelFilter,
122122
pub versions: bool,
123123
pub version: bool,
124+
pub features: bool,
124125
pub esrt: bool,
125126
pub device: Option<HardwareDeviceType>,
126127
pub compare_version: Option<String>,
@@ -679,6 +680,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
679680
print_versions(&ec);
680681
} else if args.version {
681682
print_tool_version();
683+
} else if args.features {
684+
ec.get_features().unwrap();
682685
} else if args.esrt {
683686
print_esrt();
684687
} else if let Some(compare_version_ver) = &args.compare_version {
@@ -963,6 +966,7 @@ Options:
963966
-q, --quiet... Less output per occurrence
964967
--versions List current firmware versions
965968
--version Show tool version information (Add -vv for more detailed information)
969+
--features Show features support by the firmware
966970
--esrt Display the UEFI ESRT table
967971
--device <DEVICE> Device used to compare firmware version [possible values: bios, ec, pd0, pd1, rtm01, rtm23]
968972
--compare-version Version string used to match firmware version (use with --device)

framework_lib/src/commandline/uefi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn parse(args: &[String]) -> Cli {
5757
paginate: false,
5858
versions: false,
5959
version: false,
60+
features: false,
6061
esrt: false,
6162
device: None,
6263
compare_version: None,
@@ -123,6 +124,9 @@ pub fn parse(args: &[String]) -> Cli {
123124
} else if arg == "--version" {
124125
cli.version = true;
125126
found_an_option = true;
127+
} else if arg == "--features" {
128+
cli.features = true;
129+
found_an_option = true;
126130
} else if arg == "-b" {
127131
cli.paginate = true;
128132
found_an_option = true;

0 commit comments

Comments
 (0)