From 5e2fa65e74acdd89efb0efcb211771026112ea66 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 14 Oct 2026 11:08:35 +0800 Subject: [PATCH 01/13] ci: Run clippy and tests on Windows too The lints and test jobs run on Linux only, so none of the cfg(windows) code was ever linted or tested. That is how the io_other_error lint in smart_battery's Windows read_password made it in. Signed-off-by: Daniel Schaefer --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dad703ac..a0fe2a6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,6 +145,14 @@ jobs: cargo build -p framework_tool cargo build -p framework_tool --release --features nvidia,smartmontools + # The lints and test jobs only run on Linux, so they never see the + # cfg(windows) code. Lint and test it here instead. + - name: Run cargo clippy (Windows) + run: cargo clippy -p framework_lib -p framework_tool --all-targets -- -D warnings + + - name: Run cargo test (Windows) + run: cargo test -p framework_lib + - name: Check if Windows tool can start run: target/release/framework_tool.exe --help From 2558b455b3d2bc73a1992ae69c0c0c90070443d0 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 14 Oct 2026 11:10:03 +0800 Subject: [PATCH 02/13] chromium_ec: Pass a real lpBytesReturned pointer in read_memory `Some(retb as *mut u32)` casts the u32 value 0 into a pointer, so the driver was handed a NULL lpBytesReturned. DeviceIoControl documents that as not allowed when lpOverlapped is NULL, even for operations whose returned byte count is meaningless. send_command a few lines below already does this correctly, so just match it. Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/windows.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework_lib/src/chromium_ec/windows.rs b/framework_lib/src/chromium_ec/windows.rs index 050d734d..f37e8974 100644 --- a/framework_lib/src/chromium_ec/windows.rs +++ b/framework_lib/src/chromium_ec/windows.rs @@ -97,7 +97,7 @@ pub fn read_memory(offset: u16, length: u16) -> EcResult> { let const_ptr = &mut rm as *const _ as *const ::core::ffi::c_void; let mut_ptr = &mut rm as *mut _ as *mut ::core::ffi::c_void; let ptr_size = std::mem::size_of::() as u32; - let retb: u32 = 0; + let mut returned: u32 = 0; unsafe { let device = DEVICE.lock().unwrap(); let device = if let Some(device) = *device { @@ -112,7 +112,7 @@ pub fn read_memory(offset: u16, length: u16) -> EcResult> { ptr_size, Some(mut_ptr), ptr_size, - Some(retb as *mut u32), + Some(&mut returned), None, ) .unwrap(); From 26069ab901506ae0db1959f995814e51580822be Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 20 Nov 2026 15:08:32 +0800 Subject: [PATCH 03/13] chromium_ec: Drop redundant pointer cast in send_command &mut u32 coerces to *mut u32 on its own, and read_memory now passes Some(&mut returned) without the cast, so match that. Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/windows.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework_lib/src/chromium_ec/windows.rs b/framework_lib/src/chromium_ec/windows.rs index f37e8974..d549461c 100644 --- a/framework_lib/src/chromium_ec/windows.rs +++ b/framework_lib/src/chromium_ec/windows.rs @@ -157,7 +157,7 @@ pub fn send_command(command: u16, command_version: u8, data: &[u8]) -> EcResult< cmd_len.try_into().unwrap(), Some(mut_ptr), out_len.try_into().unwrap(), - Some(&mut returned as *mut u32), + Some(&mut returned), None, ) .unwrap(); From 46ef6d2cf361c2112f5ed988949cbe08a7763d11 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 14 Oct 2026 11:13:02 +0800 Subject: [PATCH 04/13] chromium_ec: Return an error instead of panicking on failed IOCTLs Both DeviceIoControl calls ended in unwrap(), so any driver-level failure aborted the whole tool instead of surfacing as an EcError. The Linux cros_ec backend already maps its ioctl errors to EcError::DeviceError. Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/windows.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework_lib/src/chromium_ec/windows.rs b/framework_lib/src/chromium_ec/windows.rs index d549461c..e0adda97 100644 --- a/framework_lib/src/chromium_ec/windows.rs +++ b/framework_lib/src/chromium_ec/windows.rs @@ -115,7 +115,7 @@ pub fn read_memory(offset: u16, length: u16) -> EcResult> { Some(&mut returned), None, ) - .unwrap(); + .map_err(|err| EcError::DeviceError(format!("IOCTL_CROSEC_RDMEM failed with {:?}", err)))?; } let output = &rm.buffer[..(length as usize)]; Ok(output.to_vec()) @@ -160,7 +160,7 @@ pub fn send_command(command: u16, command_version: u8, data: &[u8]) -> EcResult< Some(&mut returned), None, ) - .unwrap(); + .map_err(|err| EcError::DeviceError(format!("IOCTL_CROSEC_XCMD failed with {:?}", err)))?; } match FromPrimitive::from_u32(cmd.result) { From 34635a505ce797d319a20da7ca86d1db286def5a Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 14 Oct 2026 11:23:33 +0800 Subject: [PATCH 05/13] commandline: Don't panic when the EC flash dump can't be written --dump-ec-flash unwrapped both the flash read and the file write, so a path that can't be created aborted the tool: $ framework_tool --dump-ec-flash Z:\nope\dump.bin panicked at commandline/mod.rs: Os { code: 3, kind: NotFound, .. } Create the file before reading the flash, so a bad path is reported immediately rather than after dumping all 512 KB. dump_dgpu_eeprom right below already handled this gracefully. Signed-off-by: Daniel Schaefer --- framework_lib/src/commandline/mod.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index f23d5e9e..8be0c979 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -1464,12 +1464,28 @@ fn flash_ec(ec: &CrosEc, ec_bin_path: &str, flash_type: EcFlashType, dry_run: bo } fn dump_ec_flash(ec: &CrosEc, dump_path: &str) { - let flash_bin = ec.get_entire_ec_flash().unwrap(); + // Create the file before the slow flash read, so a bad path is reported + // right away instead of after dumping all of it + #[cfg(not(feature = "uefi"))] + let mut file = match fs::File::create(dump_path) { + Ok(file) => file, + Err(err) => { + error!("Failed to create {}: {}", dump_path, err); + return; + } + }; + + let flash_bin = match ec.get_entire_ec_flash() { + Ok(flash_bin) => flash_bin, + Err(err) => { + error!("Failed to read EC flash: {:?}", err); + return; + } + }; #[cfg(not(feature = "uefi"))] - { - let mut file = fs::File::create(dump_path).unwrap(); - file.write_all(&flash_bin).unwrap(); + if let Err(err) = file.write_all(&flash_bin) { + error!("Failed to write {}: {}", dump_path, err); } #[cfg(feature = "uefi")] { From ee65a2f13e8345539926af98515ee6422c0f637d Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 14 Oct 2026 11:31:36 +0800 Subject: [PATCH 06/13] touchscreen: Stop reading past the report buffer on Windows HidD_SetOutputReport was told the report is one byte longer than the 0x40 byte buffer it was given, so the driver read one byte past the end of the stack buffer. The firmware does need that extra byte, so make the buffer 0x41 long instead of lying about its size. While here, stop treating failures as success: - ReadFile's result and bytes_read were only logged, so a failed or short read returned the zero-initialized buffer as if the device had answered. Return None instead. - Bound the response slice, which panicked when a caller asked for more than fits into a report. - HidD_SetOutputReport/HidD_GetFeature return values were ignored. - Device paths that aren't UTF-8 no longer panic. - Close the device HANDLE on drop. Untested on hardware, this system has no touchscreen. Signed-off-by: Daniel Schaefer --- framework_lib/src/touchscreen_win.rs | 93 +++++++++++++++++++++------- 1 file changed, 69 insertions(+), 24 deletions(-) diff --git a/framework_lib/src/touchscreen_win.rs b/framework_lib/src/touchscreen_win.rs index f5fd42a0..c7d47888 100644 --- a/framework_lib/src/touchscreen_win.rs +++ b/framework_lib/src/touchscreen_win.rs @@ -1,5 +1,4 @@ use hidapi::HidApi; -use std::path::Path; use crate::touchscreen::{TouchScreen, ILI_PID, ILI_VID}; #[allow(unused_imports)] @@ -19,10 +18,21 @@ use windows::{ const REPORT_ID_FIRMWARE: u8 = 0x27; const REPORT_ID_USI_VER: u8 = 0x28; +/// Size of the HID reports this device uses +const REPORT_LEN: usize = 0x40; + pub struct NativeWinTouchScreen { handle: HANDLE, } +impl Drop for NativeWinTouchScreen { + fn drop(&mut self) { + unsafe { + let _ = CloseHandle(self.handle); + } + } +} + impl TouchScreen for NativeWinTouchScreen { fn open_device(target_up: u16, skip: u8) -> Option { debug!( @@ -63,11 +73,17 @@ impl TouchScreen for NativeWinTouchScreen { // TODO: Enumerate with windows // Should enumerate and find the right one // See: https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/finding-and-opening-a-hid-collection - let path = dev_info.path().to_str().unwrap(); + let path = match dev_info.path().to_str() { + Ok(path) => path, + Err(err) => { + error!("Device path is not valid UTF-8: {:?}", err); + return None; + } + }; let res = unsafe { CreateFileW( - &HSTRING::from(Path::new(path)), + &HSTRING::from(path), FILE_GENERIC_WRITE.0 | FILE_GENERIC_READ.0, FILE_SHARE_READ | FILE_SHARE_WRITE, None, @@ -101,66 +117,95 @@ impl TouchScreen for NativeWinTouchScreen { fn send_message(&self, message_id: u8, read_len: usize, data: Vec) -> Option> { let report_id = 0x03; let data_len = data.len(); - let mut msg = [0u8; 0x40]; let msg_len = 3 + data_len; + // Microsoft docs says that the first byte of the message has to be the report ID. + // This is normal with HID implementations. + // But it seems on Windows (at least for this device's firmware) we have to set the + // length as one more than the report is long. + // Otherwise no data is returned in the read call later. + // Make the buffer that one byte longer rather than having the driver read past its end. + let mut msg = [0u8; REPORT_LEN + 1]; + if 5 + data_len > REPORT_LEN { + error!("Message data of {} B doesn't fit into a report", data_len); + return None; + } + if msg_len + read_len > REPORT_LEN { + error!("Response of {} B doesn't fit into a report", read_len); + return None; + } msg[0] = report_id; msg[1] = 0xA3; msg[2] = data_len as u8; msg[3] = read_len as u8; msg[4] = message_id; - for (i, b) in data.into_iter().enumerate() { - msg[5 + i] = b; - } + msg[5..5 + data_len].copy_from_slice(&data); - let mut buf = [0u8; 0x40]; + let mut buf = [0u8; REPORT_LEN]; buf[0] = report_id; + let mut bytes_read = 0; unsafe { debug!(" HidD_SetOutputReport {:X?}", msg); - let success = HidD_SetOutputReport( - self.handle, - // Microsoft docs says that the first byte of the message has to be the report ID. - // This is normal with HID implementations. - // But it seems on Windows (at least for this device's firmware) we have to set the - // length as one more than the buffer is long. - // Otherwise no data is returned in the read call later. - msg.as_mut_ptr() as _, - msg.len() as u32 + 1, - ); + let success = + HidD_SetOutputReport(self.handle, msg.as_mut_ptr() as _, msg.len() as u32); debug!(" Success: {}", success); + if !success { + error!("Failed to send report to touchscreen"); + return None; + } if read_len == 0 { return Some(vec![]); } - let mut bytes_read = 0; debug!(" ReadFile"); // HidD_GetFeature doesn't work, have to use ReadFile // Microsoft does recommend that // https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/obtaining-hid-reports - let res = ReadFile(self.handle, Some(&mut buf), Some(&mut bytes_read), None); - debug!(" Success: {:?}, Bytes: {}", res, bytes_read); + if let Err(err) = ReadFile(self.handle, Some(&mut buf), Some(&mut bytes_read), None) { + error!("Failed to read from touchscreen: {:?}", err); + return None; + } + debug!(" Bytes: {}", bytes_read); debug!(" Read buf: {:X?}", buf); - debug!(" Read msg: {:X?}", msg); + } + + // Without this the zero-initialized buffer would be returned as if the + // device had answered + if (bytes_read as usize) < msg_len + read_len { + error!( + "Touchscreen only returned {} B, expected at least {} B", + bytes_read, + msg_len + read_len + ); + return None; } Some(buf[msg_len..msg_len + read_len].to_vec()) } fn get_stylus_fw(&self) -> Option<()> { - let mut msg = [0u8; 0x40]; + let mut msg = [0u8; REPORT_LEN]; msg[0] = REPORT_ID_FIRMWARE; unsafe { let success = HidD_GetFeature(self.handle, msg.as_mut_ptr() as _, msg.len() as u32); debug!(" Success: {}", success); + if !success { + error!("Failed to get stylus firmware report"); + return None; + } } println!("Stylus firmware: {:X?}", msg); - let mut msg = [0u8; 0x40]; + let mut msg = [0u8; REPORT_LEN]; msg[0] = REPORT_ID_USI_VER; unsafe { let success = HidD_GetFeature(self.handle, msg.as_mut_ptr() as _, msg.len() as u32); debug!(" Success: {}", success); + if !success { + error!("Failed to get USI version report"); + return None; + } } println!("USI Version: {:X?}", msg); From 708a58a3ac86d5fea8c18a462174099bcd9bd748 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 14 Oct 2026 13:41:16 +0800 Subject: [PATCH 07/13] chromium_ec: Only offer drivers that are built for the platform All three CrosEcDriverType variants were always compiled, so on Windows clap advertised drivers whose modules don't even exist there: $ framework_tool.exe --driver [possible values: portio, cros-ec, windows] $ framework_tool.exe --driver portio --power Selected driver Portio not available. Gate the variants the same way the modules are gated. Portio is only gated on the OS and not the architecture, so that non-x86_64 targets still have at least one variant and the enum never ends up empty. Those fall through to the existing "No EC driver available" arm, hence the unreachable_patterns allows. The help text claimed portio is the default, which was only true for Linux and UEFI. Regenerate completions and the man page for the new wording and value list. Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/mod.rs | 12 ++++++++++++ framework_lib/src/commandline/clap_std.rs | 2 +- framework_tool/completions/bash/framework_tool | 2 +- framework_tool/completions/fish/framework_tool.fish | 5 ++--- framework_tool/completions/zsh/_framework_tool | 2 +- framework_tool/framework_tool.1 | 4 +--- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index 53c3da14..4737adc4 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -2140,11 +2140,19 @@ impl CrosEc { } } +/// Drivers that can be built for the current platform +/// +/// Only gated by OS, not by architecture, so that there's always at least one +/// variant. Whether the driver is actually usable on this machine is decided by +/// `available_drivers`. #[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))] #[derive(Clone, Debug, Copy, PartialEq)] pub enum CrosEcDriverType { + #[cfg(not(windows))] Portio, + #[cfg(target_os = "linux")] CrosEc, + #[cfg(windows)] Windows, } @@ -2173,6 +2181,9 @@ impl CrosEcDriver for CrosEc { } // TODO: Change this function to return EcResult instead and print the error only in UI code + // The catch-all arm is unreachable unless a variant is built without its driver, + // which only happens for Portio on non-x86_64 + #[allow(unreachable_patterns)] print_err(match self.driver { #[cfg(all(not(windows), target_arch = "x86_64"))] Some(CrosEcDriverType::Portio) => portio::read_memory(offset, length), @@ -2204,6 +2215,7 @@ impl CrosEcDriver for CrosEc { ))); } + #[allow(unreachable_patterns)] match self.driver { #[cfg(all(not(windows), target_arch = "x86_64"))] Some(CrosEcDriverType::Portio) => portio::send_command(command, command_version, data), diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index 323f3f37..e0636e13 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -361,7 +361,7 @@ struct ClapCli { #[arg(long)] hash: Option, - /// Select which driver is used. By default portio is used + /// Select which driver is used to talk to the EC. Defaults to the first available one #[clap(value_enum)] #[arg(long)] driver: Option, diff --git a/framework_tool/completions/bash/framework_tool b/framework_tool/completions/bash/framework_tool index 9806ab61..b53cd9a2 100755 --- a/framework_tool/completions/bash/framework_tool +++ b/framework_tool/completions/bash/framework_tool @@ -206,7 +206,7 @@ _framework_tool() { return 0 ;; --driver) - COMPREPLY=($(compgen -W "portio cros-ec windows" -- "${cur}")) + COMPREPLY=($(compgen -W "portio cros-ec" -- "${cur}")) return 0 ;; --pd-addrs) diff --git a/framework_tool/completions/fish/framework_tool.fish b/framework_tool/completions/fish/framework_tool.fish index 129cead3..4143ebac 100644 --- a/framework_tool/completions/fish/framework_tool.fish +++ b/framework_tool/completions/fish/framework_tool.fish @@ -72,9 +72,8 @@ cancel-jump\t'' disable-jump\t''" complete -c framework_tool -l ec-hib-delay -d 'Get or set EC hibernate delay (S5 to G3)' -r complete -c framework_tool -l hash -d 'Hash a file of arbitrary data' -r -F -complete -c framework_tool -l driver -d 'Select which driver is used. By default portio is used' -r -f -a "portio\t'' -cros-ec\t'' -windows\t''" +complete -c framework_tool -l driver -d 'Select which driver is used to talk to the EC. Defaults to the first available one' -r -f -a "portio\t'' +cros-ec\t''" complete -c framework_tool -l pd-addrs -d 'Specify I2C addresses of the PD chips (Advanced)' -r complete -c framework_tool -l pd-ports -d 'Specify I2C ports of the PD chips (Advanced)' -r complete -c framework_tool -l flash-gpu-descriptor-file -d 'File to write to the gpu EEPROM' -r -F diff --git a/framework_tool/completions/zsh/_framework_tool b/framework_tool/completions/zsh/_framework_tool index c820518b..2c204bb6 100644 --- a/framework_tool/completions/zsh/_framework_tool +++ b/framework_tool/completions/zsh/_framework_tool @@ -59,7 +59,7 @@ _framework_tool() { '--reboot-ec=[Control EC RO/RW jump]:REBOOT_EC:(reboot jump-ro jump-rw cancel-jump disable-jump)' \ '--ec-hib-delay=[Get or set EC hibernate delay (S5 to G3)]::EC_HIB_DELAY:_default' \ '--hash=[Hash a file of arbitrary data]:HASH:_files' \ -'--driver=[Select which driver is used. By default portio is used]:DRIVER:(portio cros-ec windows)' \ +'--driver=[Select which driver is used to talk to the EC. Defaults to the first available one]:DRIVER:(portio cros-ec)' \ '*--pd-addrs=[Specify I2C addresses of the PD chips (Advanced)]:PD_ADDRS:_default:PD_ADDRS:_default:PD_ADDRS:_default' \ '*--pd-ports=[Specify I2C ports of the PD chips (Advanced)]:PD_PORTS:_default:PD_PORTS:_default:PD_PORTS:_default' \ '--flash-gpu-descriptor-file=[File to write to the gpu EEPROM]:FLASH_GPU_DESCRIPTOR_FILE:_files' \ diff --git a/framework_tool/framework_tool.1 b/framework_tool/framework_tool.1 index 8e3f6ceb..13fc6cfc 100644 --- a/framework_tool/framework_tool.1 +++ b/framework_tool/framework_tool.1 @@ -397,7 +397,7 @@ Show saved EC panic info Hash a file of arbitrary data .TP \fB\-\-driver\fR \fI\fR -Select which driver is used. By default portio is used +Select which driver is used to talk to the EC. Defaults to the first available one .br .br @@ -407,8 +407,6 @@ Select which driver is used. By default portio is used portio .IP \(bu 2 cros\-ec -.IP \(bu 2 -windows .RE .TP \fB\-\-pd\-addrs\fR \fI...\fR From ae320f3994e4e4f238f9ed7ebbc21f669216d65d Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 14 Oct 2026 13:49:10 +0800 Subject: [PATCH 08/13] commandline: Only touch the touchscreen and stylus on Laptop 12 Laptop 12 is the only system with a touchscreen and stylus, but --stylus-battery, --touchscreen-enable and the touchscreen part of --versions ran everywhere. --stylus-battery was the worst of them: print_stylus_battery_level looped forever, only logging at debug level when no stylus answered. On a Laptop 16 it never returned, it had to be killed. Gate it on the platform and bound the retries, so it also terminates on a Laptop 12 with no stylus paired. print_himax_fw_ver was likewise called on every platform in --versions, while print_fw_ver next to it was already gated. Signed-off-by: Daniel Schaefer --- framework_lib/src/commandline/mod.rs | 37 ++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 8be0c979..6f820a64 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -541,16 +541,35 @@ fn active_mode(mode: &FwMode, reference: FwMode) -> &'static str { } } +/// Whether this system can have a touchscreen and stylus +/// +/// So far only the Framework Laptop 12 has them. +#[cfg(feature = "hidapi")] +fn has_touchscreen() -> bool { + smbios::get_platform().and_then(Platform::which_family) == Some(PlatformFamily::Framework12) +} + +/// How often to ask the stylus for its battery level before giving up +/// +/// The stylus only answers while it's awake, so a few tries are needed. But it +/// has to be bounded, otherwise this never returns when no stylus is around. +#[cfg(feature = "hidapi")] +const STYLUS_BATTERY_TRIES: u32 = 50; + #[cfg(feature = "hidapi")] fn print_stylus_battery_level() { - loop { + if !has_touchscreen() { + error!("This system has no stylus"); + return; + } + for _ in 0..STYLUS_BATTERY_TRIES { if let Some(level) = touchscreen::get_battery_level() { println!("Stylus Battery Strength: {}%", level); return; - } else { - debug!("Stylus Battery Strength: Unknown"); } + debug!("Stylus Battery Strength: Unknown"); } + println!("Stylus Battery Strength: Unknown"); } fn print_versions(ec: &CrosEc) { @@ -860,13 +879,9 @@ fn print_versions(ec: &CrosEc) { let _ignore_err = print_touchpad_fw_ver(); #[cfg(feature = "hidapi")] - { + if has_touchscreen() { let _ignore_err = touchscreen::print_himax_fw_ver(); - if smbios::get_platform().and_then(Platform::which_family) - == Some(PlatformFamily::Framework12) - { - let _ignore_err = touchscreen::print_fw_ver(); - } + let _ignore_err = touchscreen::print_fw_ver(); } #[cfg(feature = "hidapi")] print_dp_hdmi_details(false); @@ -1880,7 +1895,9 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { ec.set_tablet_mode(mode); } else if let Some(_enable) = &args.touchscreen_enable { #[cfg(feature = "hidapi")] - if touchscreen::enable_touch(*_enable).is_none() { + if !has_touchscreen() { + error!("This system has no touchscreen"); + } else if touchscreen::enable_touch(*_enable).is_none() { error!("Failed to enable/disable touch"); } } else if let Some(_intensity) = &args.haptic_intensity { From 11c5684092e01da99088fa8a5467cc4725e25e97 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 20 Nov 2026 15:13:35 +0800 Subject: [PATCH 09/13] chromium_ec: Match the Windows driver's read_memory bounds crosecbus rejects a memory map read when offset >= EC_MEMMAP_SIZE - bytes, so a read ending exactly at the end of the 255 byte map fails, even though the shared check in CrosEc::read_memory lets it through. Check the same bound up front so the user gets an error saying why instead of a generic IOCTL failure. The other drivers can still read the whole map. Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/windows.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/framework_lib/src/chromium_ec/windows.rs b/framework_lib/src/chromium_ec/windows.rs index e0adda97..877a5692 100644 --- a/framework_lib/src/chromium_ec/windows.rs +++ b/framework_lib/src/chromium_ec/windows.rs @@ -88,6 +88,14 @@ pub fn read_memory(offset: u16, length: u16) -> EcResult> { if !init() { return Err(EcError::DeviceError("Failed to initialize".to_string())); } + // The driver rejects reads that end at the last byte of the memory map, + // so it can only read up to EC_MEMMAP_SIZE - 1 bytes + if offset as u32 + length as u32 >= EC_MEMMAP_SIZE as u32 { + return Err(EcError::DeviceError(format!( + "Windows driver requires offset + length < {:#X} (offset={:#X}, length={:#X})", + EC_MEMMAP_SIZE, offset, length + ))); + } let mut rm = CrosEcReadMem { offset: offset as u32, bytes: length as u32, From eeeca2862df40b2fc50a3fcedcc665369fa9b09d Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 20 Nov 2026 16:52:38 +0800 Subject: [PATCH 10/13] commandline: Show the Himax touchscreen version on Laptop 13 again The previous commit gated print_himax_fw_ver behind the Laptop 12 check, but the Himax touchscreen is the one Laptop 13 can have, so --versions stopped showing it there. On Laptop 12 print_fw_ver already prints the Himax version itself, so calling both printed it twice. Call print_fw_ver on Laptop 12 and print_himax_fw_ver everywhere else. Rename has_touchscreen to has_ili_touchscreen, because it is only about the ILI touchscreen and stylus. Signed-off-by: Daniel Schaefer Co-Authored-By: Claude Opus 5.5 --- framework_lib/src/commandline/mod.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 6f820a64..b3fdd878 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -541,11 +541,12 @@ fn active_mode(mode: &FwMode, reference: FwMode) -> &'static str { } } -/// Whether this system can have a touchscreen and stylus +/// Whether this system can have the ILI touchscreen and stylus /// -/// So far only the Framework Laptop 12 has them. +/// So far only the Framework Laptop 12 has them. Other systems may have a +/// Himax touchscreen, which is handled separately. #[cfg(feature = "hidapi")] -fn has_touchscreen() -> bool { +fn has_ili_touchscreen() -> bool { smbios::get_platform().and_then(Platform::which_family) == Some(PlatformFamily::Framework12) } @@ -558,7 +559,7 @@ const STYLUS_BATTERY_TRIES: u32 = 50; #[cfg(feature = "hidapi")] fn print_stylus_battery_level() { - if !has_touchscreen() { + if !has_ili_touchscreen() { error!("This system has no stylus"); return; } @@ -879,9 +880,12 @@ fn print_versions(ec: &CrosEc) { let _ignore_err = print_touchpad_fw_ver(); #[cfg(feature = "hidapi")] - if has_touchscreen() { - let _ignore_err = touchscreen::print_himax_fw_ver(); + if has_ili_touchscreen() { + // Also prints the Himax touchscreen version let _ignore_err = touchscreen::print_fw_ver(); + } else { + // Laptop 13 can have a Himax touchscreen + let _ignore_err = touchscreen::print_himax_fw_ver(); } #[cfg(feature = "hidapi")] print_dp_hdmi_details(false); @@ -1895,7 +1899,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { ec.set_tablet_mode(mode); } else if let Some(_enable) = &args.touchscreen_enable { #[cfg(feature = "hidapi")] - if !has_touchscreen() { + if !has_ili_touchscreen() { error!("This system has no touchscreen"); } else if touchscreen::enable_touch(*_enable).is_none() { error!("Failed to enable/disable touch"); From f7ffc71abb1beb69e22d81d9183bee9a65edb940 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 20 Nov 2026 16:52:51 +0800 Subject: [PATCH 11/13] EXAMPLES: Update the --driver help text It changed when the driver enum was gated by platform. The help output shown here is from Linux, where --driver now only accepts portio and cros-ec. Passing --driver windows is rejected by the argument parser instead of failing later when the driver is not found. Signed-off-by: Daniel Schaefer Co-Authored-By: Claude Opus 5.5 --- EXAMPLES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index 759c9f99..131aa1bf 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -118,7 +118,7 @@ Options: --hash Hash a file of arbitrary data --driver - Select which driver is used. By default portio is used [possible values: portio, cros-ec, windows] + Select which driver is used to talk to the EC. Defaults to the first available one [possible values: portio, cros-ec] --pd-addrs Specify I2C addresses of the PD chips (Advanced) --pd-ports From 771081edbbd0d5006fbc8d50202db2d2aa8c0453 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 20 Nov 2026 16:53:22 +0800 Subject: [PATCH 12/13] commandline: Remove the empty dump file when the EC flash read fails The dump file is now created before reading the flash, so a failed read left an empty file behind, which could be mistaken for a dump. Remove it again. It has to be closed first, otherwise Windows can't delete it. Signed-off-by: Daniel Schaefer Co-Authored-By: Claude Opus 5.5 --- framework_lib/src/commandline/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index b3fdd878..95c45a8c 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -1498,6 +1498,12 @@ fn dump_ec_flash(ec: &CrosEc, dump_path: &str) { Ok(flash_bin) => flash_bin, Err(err) => { error!("Failed to read EC flash: {:?}", err); + // Don't leave an empty file behind that looks like a dump + #[cfg(not(feature = "uefi"))] + { + drop(file); + let _ = fs::remove_file(dump_path); + } return; } }; From ed1fd8393010992d267f241ccd9c047cb49fa401 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 20 Nov 2026 16:53:49 +0800 Subject: [PATCH 13/13] power: Don't report 0% charge before an update when LFCC is 0 charge_percentage falls back to 0 when the last full charge capacity is 0. print_battery_information already says the level is unknown in that case, but check_update_ready printed "Current charge is: 0%". Say it's unknown there too. The update is still refused, as before. Signed-off-by: Daniel Schaefer Co-Authored-By: Claude Opus 5.5 --- framework_lib/src/power.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework_lib/src/power.rs b/framework_lib/src/power.rs index cbb0382b..073812bc 100644 --- a/framework_lib/src/power.rs +++ b/framework_lib/src/power.rs @@ -883,7 +883,11 @@ pub fn check_update_ready(power_info: &PowerInfo) -> bool { Some(battery) if power_info.ac_present && battery.charge_percentage > 20 => true, Some(battery) => { println!("Please plug in AC. If the battery is connected, charge it to at least 20% before proceeding."); - println!("Current charge is: {}%", battery.charge_percentage); + if battery.last_full_charge_capacity == 0 { + println!("Current charge is: Unknown (LFCC is 0)"); + } else { + println!("Current charge is: {}%", battery.charge_percentage); + } false } }