Skip to content

Commit 74f3aef

Browse files
committed
Add --sysinfo command
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent ca8d682 commit 74f3aef

10 files changed

Lines changed: 104 additions & 1 deletion

File tree

EXAMPLES_ADVANCED.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ Intel ME Status (SMBIOS Type 0xDB)
192192
HFSTS6: 0x00000000
193193
```
194194

195+
## EC System Info
196+
197+
Show which EC image is running, why the EC last reset and its locked state
198+
(same as `ectool sysinfo`).
199+
200+
```
201+
> framework_tool --sysinfo
202+
EC System Info
203+
Current Image: RO
204+
Reset Flags: 0x00000048
205+
PowerOn
206+
Hibernate
207+
Flags: 0x00000020
208+
InManualRecovery
209+
```
210+
195211
## Manually overriding tablet mode status
196212

197213
If you have a suspicion that the embedded controller does not control tablet

framework_lib/src/chromium_ec/command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub enum EcCommands {
2828
/// Erase section of EC flash
2929
FlashErase = 0x13,
3030
FlashProtect = 0x15,
31+
Sysinfo = 0x1C,
3132
PwmSetFanTargetRpm = 0x0021,
3233
PwmGetKeyboardBacklight = 0x0022,
3334
PwmSetKeyboardBacklight = 0x0023,

framework_lib/src/chromium_ec/commands.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,44 @@ impl EcRequest<EcResponseFlashProtect> for EcRequestFlashProtect {
154154
}
155155
}
156156

157+
#[repr(C, packed)]
158+
pub struct EcRequestSysinfo {}
159+
160+
/// Bits of EcResponseSysinfo flags (enum sysinfo_flags)
161+
#[repr(usize)]
162+
#[derive(Debug, FromPrimitive)]
163+
pub enum SysinfoFlag {
164+
/// Write protect is asserted, debug features are disabled
165+
Locked,
166+
/// Locked even if write protect is deasserted
167+
ForceLocked,
168+
/// Jumping between images is enabled
169+
JumpEnabled,
170+
/// EC jumped directly to the current image at boot
171+
JumpedToCurrentImage,
172+
/// EC will reboot when the system shuts down
173+
RebootAtShutdown,
174+
/// System is in manual recovery mode
175+
InManualRecovery,
176+
Count,
177+
}
178+
179+
#[repr(C, packed)]
180+
pub struct EcResponseSysinfo {
181+
/// Reset flags of the current boot. See enum EcResetFlag
182+
pub reset_flags: u32,
183+
/// Which EC image is currently in-use. See enum EcCurrentImage
184+
pub current_image: u32,
185+
/// See enum SysinfoFlag
186+
pub flags: u32,
187+
}
188+
189+
impl EcRequest<EcResponseSysinfo> for EcRequestSysinfo {
190+
fn command_id() -> EcCommands {
191+
EcCommands::Sysinfo
192+
}
193+
}
194+
157195
#[repr(C, packed)]
158196
pub struct EcRequestPwmSetKeyboardBacklight {
159197
pub percent: u8,

framework_lib/src/chromium_ec/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,38 @@ impl CrosEc {
19021902
}
19031903
}
19041904

1905+
pub fn get_sysinfo(&self) -> EcResult<()> {
1906+
let res = EcRequestSysinfo {}.send_command(self)?;
1907+
let current_image = match res.current_image {
1908+
1 => EcCurrentImage::RO,
1909+
2 => EcCurrentImage::RW,
1910+
_ => EcCurrentImage::Unknown,
1911+
};
1912+
println!("EC System Info");
1913+
println!(" Current Image: {:?}", current_image);
1914+
println!(" Reset Flags: {:#010X}", { res.reset_flags });
1915+
for flag in 0..(EcResetFlag::Count as usize) {
1916+
if ((1 << flag) & res.reset_flags) > 0 {
1917+
// Safe to unwrap unless coding mistake
1918+
println!(
1919+
" {:?}",
1920+
<EcResetFlag as FromPrimitive>::from_usize(flag).unwrap()
1921+
);
1922+
}
1923+
}
1924+
println!(" Flags: {:#010X}", { res.flags });
1925+
for flag in 0..(SysinfoFlag::Count as usize) {
1926+
if ((1 << flag) & res.flags) > 0 {
1927+
// Safe to unwrap unless coding mistake
1928+
println!(
1929+
" {:?}",
1930+
<SysinfoFlag as FromPrimitive>::from_usize(flag).unwrap()
1931+
);
1932+
}
1933+
}
1934+
Ok(())
1935+
}
1936+
19051937
pub fn get_uptime_info(&self) -> EcResult<()> {
19061938
let res = EcRequestGetUptimeInfo {}.send_command(self)?;
19071939
let t_since_boot = Duration::from_millis(res.time_since_ec_boot.into());

framework_lib/src/commandline/clap_std.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ struct ClapCli {
283283
#[arg(long)]
284284
ec_hib_delay: Option<Option<u32>>,
285285

286+
/// Show system info (reset flags, current image, locked state)
287+
#[arg(long)]
288+
sysinfo: bool,
289+
286290
#[arg(long)]
287291
uptimeinfo: bool,
288292

@@ -575,6 +579,7 @@ pub fn parse(args: &[String]) -> Cli {
575579
console: args.console,
576580
reboot_ec: args.reboot_ec,
577581
ec_hib_delay: args.ec_hib_delay,
582+
sysinfo: args.sysinfo,
578583
uptimeinfo: args.uptimeinfo,
579584
s0ix_counter: args.s0ix_counter,
580585
hash: args.hash.map(|x| x.into_os_string().into_string().unwrap()),

framework_lib/src/commandline/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ pub struct Cli {
243243
pub console: Option<ConsoleArg>,
244244
pub reboot_ec: Option<RebootEcArg>,
245245
pub ec_hib_delay: Option<Option<u32>>,
246+
pub sysinfo: bool,
246247
pub uptimeinfo: bool,
247248
pub s0ix_counter: bool,
248249
pub hash: Option<String>,
@@ -334,6 +335,7 @@ pub fn parse(args: &[String]) -> Cli {
334335
console: cli.console,
335336
reboot_ec: cli.reboot_ec,
336337
// ec_hib_delay
338+
sysinfo: cli.sysinfo,
337339
uptimeinfo: cli.uptimeinfo,
338340
s0ix_counter: cli.s0ix_counter,
339341
hash: cli.hash,
@@ -1573,6 +1575,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
15731575
print_err(ec.set_ec_hib_delay(*delay));
15741576
}
15751577
print_err(ec.get_ec_hib_delay());
1578+
} else if args.sysinfo {
1579+
print_err(ec.get_sysinfo());
15761580
} else if args.uptimeinfo {
15771581
print_err(ec.get_uptime_info());
15781582
} else if args.s0ix_counter {
@@ -1977,6 +1981,7 @@ Options:
19771981
--flash-rw-ec <FLASH_EC> Flash EC with new firmware from file
19781982
--reboot-ec Control EC RO/RW jump [possible values: reboot, jump-ro, jump-rw, cancel-jump, disable-jump]
19791983
--ec-hib-delay [<SECONDS>] Get or set EC hibernate delay (S5 to G3)
1984+
--sysinfo Show system info (reset flags, current image, locked state)
19801985
--uptimeinfo Show EC uptime information
19811986
--s0ix-counter Show S0ix counter
19821987
--intrusion Show status of intrusion switch

framework_lib/src/commandline/uefi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub fn parse(args: &[String]) -> Cli {
8989
console: None,
9090
reboot_ec: None,
9191
ec_hib_delay: None,
92+
sysinfo: false,
9293
uptimeinfo: false,
9394
s0ix_counter: false,
9495
hash: None,
@@ -540,6 +541,9 @@ pub fn parse(args: &[String]) -> Cli {
540541
Some(None)
541542
};
542543
found_an_option = true;
544+
} else if arg == "--sysinfo" {
545+
cli.sysinfo = true;
546+
found_an_option = true;
543547
} else if arg == "--uptimeinfo" {
544548
cli.uptimeinfo = true;
545549
found_an_option = true;

framework_tool/completions/bash/framework_tool

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _framework_tool() {
2323

2424
case "${cmd}" in
2525
framework_tool)
26-
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"
26+
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"
2727
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
2828
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
2929
return 0

framework_tool/completions/fish/framework_tool.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ complete -c framework_tool -l intrusion -d 'Show status of intrusion switch'
103103
complete -c framework_tool -l inputdeck -d 'Show status of the input modules'
104104
complete -c framework_tool -l expansion-bay -d 'Show status of the expansion bay (Laptop 16 only)'
105105
complete -c framework_tool -l stylus-battery -d 'Check stylus battery level (USI 2.0 stylus only)'
106+
complete -c framework_tool -l sysinfo -d 'Show system info (reset flags, current image, locked state)'
106107
complete -c framework_tool -l uptimeinfo
107108
complete -c framework_tool -l s0ix-counter
108109
complete -c framework_tool -s t -l test -d 'Run self-test to check if interaction with EC is possible'

framework_tool/completions/zsh/_framework_tool

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ _framework_tool() {
8787
'--inputdeck[Show status of the input modules]' \
8888
'--expansion-bay[Show status of the expansion bay (Laptop 16 only)]' \
8989
'--stylus-battery[Check stylus battery level (USI 2.0 stylus only)]' \
90+
'--sysinfo[Show system info (reset flags, current image, locked state)]' \
9091
'--uptimeinfo[]' \
9192
'--s0ix-counter[]' \
9293
'-t[Run self-test to check if interaction with EC is possible]' \

0 commit comments

Comments
 (0)