diff --git a/EXAMPLES_ADVANCED.md b/EXAMPLES_ADVANCED.md index 0a457d5..5461a41 100644 --- a/EXAMPLES_ADVANCED.md +++ b/EXAMPLES_ADVANCED.md @@ -192,6 +192,22 @@ Intel ME Status (SMBIOS Type 0xDB) HFSTS6: 0x00000000 ``` +## EC System Info + +Show which EC image is running, why the EC last reset and its locked state +(same as `ectool sysinfo`). + +``` +> framework_tool --sysinfo +EC System Info + Current Image: RO + Reset Flags: 0x00000048 + PowerOn + Hibernate + Flags: 0x00000020 + InManualRecovery +``` + ## Manually overriding tablet mode status If you have a suspicion that the embedded controller does not control tablet diff --git a/framework_lib/src/chromium_ec/command.rs b/framework_lib/src/chromium_ec/command.rs index 14b865b..6774922 100644 --- a/framework_lib/src/chromium_ec/command.rs +++ b/framework_lib/src/chromium_ec/command.rs @@ -28,6 +28,7 @@ pub enum EcCommands { /// Erase section of EC flash FlashErase = 0x13, FlashProtect = 0x15, + Sysinfo = 0x1C, PwmSetFanTargetRpm = 0x0021, PwmGetKeyboardBacklight = 0x0022, PwmSetKeyboardBacklight = 0x0023, diff --git a/framework_lib/src/chromium_ec/commands.rs b/framework_lib/src/chromium_ec/commands.rs index 5dc0c91..96cab5b 100644 --- a/framework_lib/src/chromium_ec/commands.rs +++ b/framework_lib/src/chromium_ec/commands.rs @@ -154,6 +154,44 @@ impl EcRequest for EcRequestFlashProtect { } } +#[repr(C, packed)] +pub struct EcRequestSysinfo {} + +/// Bits of EcResponseSysinfo flags (enum sysinfo_flags) +#[repr(usize)] +#[derive(Debug, FromPrimitive)] +pub enum SysinfoFlag { + /// Write protect is asserted, debug features are disabled + Locked, + /// Locked even if write protect is deasserted + ForceLocked, + /// Jumping between images is enabled + JumpEnabled, + /// EC jumped directly to the current image at boot + JumpedToCurrentImage, + /// EC will reboot when the system shuts down + RebootAtShutdown, + /// System is in manual recovery mode + InManualRecovery, + Count, +} + +#[repr(C, packed)] +pub struct EcResponseSysinfo { + /// Reset flags of the current boot. See enum EcResetFlag + pub reset_flags: u32, + /// Which EC image is currently in-use. See enum EcCurrentImage + pub current_image: u32, + /// See enum SysinfoFlag + pub flags: u32, +} + +impl EcRequest for EcRequestSysinfo { + fn command_id() -> EcCommands { + EcCommands::Sysinfo + } +} + #[repr(C, packed)] pub struct EcRequestPwmSetKeyboardBacklight { pub percent: u8, diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index f6fe27e..d1efd7e 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -1902,6 +1902,38 @@ impl CrosEc { } } + pub fn get_sysinfo(&self) -> EcResult<()> { + let res = EcRequestSysinfo {}.send_command(self)?; + let current_image = match res.current_image { + 1 => EcCurrentImage::RO, + 2 => EcCurrentImage::RW, + _ => EcCurrentImage::Unknown, + }; + println!("EC System Info"); + println!(" Current Image: {:?}", current_image); + println!(" Reset Flags: {:#010X}", { res.reset_flags }); + for flag in 0..(EcResetFlag::Count as usize) { + if ((1 << flag) & res.reset_flags) > 0 { + // Safe to unwrap unless coding mistake + println!( + " {:?}", + ::from_usize(flag).unwrap() + ); + } + } + println!(" Flags: {:#010X}", { res.flags }); + for flag in 0..(SysinfoFlag::Count as usize) { + if ((1 << flag) & res.flags) > 0 { + // Safe to unwrap unless coding mistake + println!( + " {:?}", + ::from_usize(flag).unwrap() + ); + } + } + Ok(()) + } + pub fn get_uptime_info(&self) -> EcResult<()> { let res = EcRequestGetUptimeInfo {}.send_command(self)?; let t_since_boot = Duration::from_millis(res.time_since_ec_boot.into()); diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index 76ac18f..cdb4c34 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -283,6 +283,10 @@ struct ClapCli { #[arg(long)] ec_hib_delay: Option>, + /// Show system info (reset flags, current image, locked state) + #[arg(long)] + sysinfo: bool, + #[arg(long)] uptimeinfo: bool, @@ -575,6 +579,7 @@ pub fn parse(args: &[String]) -> Cli { console: args.console, reboot_ec: args.reboot_ec, ec_hib_delay: args.ec_hib_delay, + sysinfo: args.sysinfo, uptimeinfo: args.uptimeinfo, s0ix_counter: args.s0ix_counter, hash: args.hash.map(|x| x.into_os_string().into_string().unwrap()), diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index dc0e7d2..c56ac92 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -243,6 +243,7 @@ pub struct Cli { pub console: Option, pub reboot_ec: Option, pub ec_hib_delay: Option>, + pub sysinfo: bool, pub uptimeinfo: bool, pub s0ix_counter: bool, pub hash: Option, @@ -334,6 +335,7 @@ pub fn parse(args: &[String]) -> Cli { console: cli.console, reboot_ec: cli.reboot_ec, // ec_hib_delay + sysinfo: cli.sysinfo, uptimeinfo: cli.uptimeinfo, s0ix_counter: cli.s0ix_counter, hash: cli.hash, @@ -1573,6 +1575,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { print_err(ec.set_ec_hib_delay(*delay)); } print_err(ec.get_ec_hib_delay()); + } else if args.sysinfo { + print_err(ec.get_sysinfo()); } else if args.uptimeinfo { print_err(ec.get_uptime_info()); } else if args.s0ix_counter { @@ -1977,6 +1981,7 @@ Options: --flash-rw-ec Flash EC with new firmware from file --reboot-ec Control EC RO/RW jump [possible values: reboot, jump-ro, jump-rw, cancel-jump, disable-jump] --ec-hib-delay [] Get or set EC hibernate delay (S5 to G3) + --sysinfo Show system info (reset flags, current image, locked state) --uptimeinfo Show EC uptime information --s0ix-counter Show S0ix counter --intrusion Show status of intrusion switch diff --git a/framework_lib/src/commandline/uefi.rs b/framework_lib/src/commandline/uefi.rs index b3bd227..748c913 100644 --- a/framework_lib/src/commandline/uefi.rs +++ b/framework_lib/src/commandline/uefi.rs @@ -89,6 +89,7 @@ pub fn parse(args: &[String]) -> Cli { console: None, reboot_ec: None, ec_hib_delay: None, + sysinfo: false, uptimeinfo: false, s0ix_counter: false, hash: None, @@ -540,6 +541,9 @@ pub fn parse(args: &[String]) -> Cli { Some(None) }; found_an_option = true; + } else if arg == "--sysinfo" { + cli.sysinfo = true; + found_an_option = true; } else if arg == "--uptimeinfo" { cli.uptimeinfo = true; found_an_option = true; diff --git a/framework_tool/completions/bash/framework_tool b/framework_tool/completions/bash/framework_tool index e542c17..d8b39a9 100755 --- a/framework_tool/completions/bash/framework_tool +++ b/framework_tool/completions/bash/framework_tool @@ -23,7 +23,7 @@ _framework_tool() { case "${cmd}" in framework_tool) - opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --smartbattery --smartbattery-auth --thermal --sensors --fansetduty --fansetrpm --autofanctrl --pdports --pdports-chromebook --info --meinfo --pd-info --pd-reset --pd-disable --pd-enable --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-full-ec --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --ps2-enable --tablet-mode --touchscreen-enable --haptic-intensity --click-force --stylus-battery --console --reboot-ec --ec-hib-delay --uptimeinfo --s0ix-counter --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --validate-gpu-descriptor-file --nvidia --host-command --generate-completions --help" + opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --smartbattery --smartbattery-auth --thermal --sensors --fansetduty --fansetrpm --autofanctrl --pdports --pdports-chromebook --info --meinfo --pd-info --pd-reset --pd-disable --pd-enable --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-full-ec --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --ps2-enable --tablet-mode --touchscreen-enable --haptic-intensity --click-force --stylus-battery --console --reboot-ec --ec-hib-delay --sysinfo --uptimeinfo --s0ix-counter --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --validate-gpu-descriptor-file --nvidia --host-command --generate-completions --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/framework_tool/completions/fish/framework_tool.fish b/framework_tool/completions/fish/framework_tool.fish index 815f2b4..0be6254 100644 --- a/framework_tool/completions/fish/framework_tool.fish +++ b/framework_tool/completions/fish/framework_tool.fish @@ -103,6 +103,7 @@ complete -c framework_tool -l intrusion -d 'Show status of intrusion switch' complete -c framework_tool -l inputdeck -d 'Show status of the input modules' complete -c framework_tool -l expansion-bay -d 'Show status of the expansion bay (Laptop 16 only)' complete -c framework_tool -l stylus-battery -d 'Check stylus battery level (USI 2.0 stylus only)' +complete -c framework_tool -l sysinfo -d 'Show system info (reset flags, current image, locked state)' complete -c framework_tool -l uptimeinfo complete -c framework_tool -l s0ix-counter complete -c framework_tool -s t -l test -d 'Run self-test to check if interaction with EC is possible' diff --git a/framework_tool/completions/zsh/_framework_tool b/framework_tool/completions/zsh/_framework_tool index edc7b7e..d005f94 100644 --- a/framework_tool/completions/zsh/_framework_tool +++ b/framework_tool/completions/zsh/_framework_tool @@ -87,6 +87,7 @@ _framework_tool() { '--inputdeck[Show status of the input modules]' \ '--expansion-bay[Show status of the expansion bay (Laptop 16 only)]' \ '--stylus-battery[Check stylus battery level (USI 2.0 stylus only)]' \ +'--sysinfo[Show system info (reset flags, current image, locked state)]' \ '--uptimeinfo[]' \ '--s0ix-counter[]' \ '-t[Run self-test to check if interaction with EC is possible]' \