diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d02ce8..1c5ba4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: jobs: lint: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 @@ -16,10 +16,11 @@ jobs: - name: clippy env: BASEDIR: "." - run: cargo clippy + run: cargo clippy --target x86_64-unknown-uefi -- -D warnings + continue-on-error: true build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 diff --git a/Cargo.lock b/Cargo.lock index 1a8bd0a..7981593 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "coreboot-fs" @@ -25,9 +25,9 @@ dependencies = [ [[package]] name = "downcast-rs" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "intel-spi" @@ -35,7 +35,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a896a575e2acf5f38da6b5eaf0e01b71c198cea0967046af864bda951102b2c6" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "coreboot-fs", "libc", "redox_intelflash", @@ -43,26 +43,26 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libredox" -version = "0.0.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "libc", "redox_syscall", ] [[package]] name = "orbclient" -version = "0.3.47" +version = "0.3.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52f0d54bde9774d3a51dcf281a5def240c71996bc6ca05d2c847ec8b2b216166" +checksum = "ba0b26cec2e24f08ed8bb31519a9333140a6599b867dac464bb150bdb796fd43" dependencies = [ "libredox", ] @@ -101,33 +101,33 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.6.0", ] [[package]] name = "redox_uefi" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1ef8d2afbe5adfc257e0847f360d0f175e7012c4fa984a284966b54ad5834d" +checksum = "c5d69301333534a04b380995f5d9e604f46a7cbd8d8c62c996ee27447efdeba4" [[package]] name = "redox_uefi_alloc" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12fe0357fd0ecc7c7de510c9add51a52a9268c3fa5890f9c8dbef890e4b2d1f6" +checksum = "1df364cdf289d9df9201f147aeeb5e7387f29f0824bee2e41e960eb98eaf03f1" dependencies = [ "redox_uefi", ] [[package]] name = "redox_uefi_std" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a19dfc2a64c4a152fff1819c6ce74460c322a46da9c812ffaa1282260c19ec2" +checksum = "b81203f45b2e08804d80274a2951f1615828d9aa5629d3a5d267878c70feb96d" dependencies = [ "redox_uefi", "redox_uefi_alloc", @@ -142,7 +142,7 @@ checksum = "3b4428b459c1c06e7a3ecf1dd3e863f4e7442a474463094af6a702e3b860ec25" [[package]] name = "system76_ectool" version = "0.3.8" -source = "git+https://github.com/system76/ec.git#38d4666a9007b6d36e344bbc36109876e519028e" +source = "git+https://github.com/system76/ec.git#3d8204c3f40b4de1e3b94f2c1aaca5f29a80122e" dependencies = [ "downcast-rs", "redox_hwio", diff --git a/Cargo.toml b/Cargo.toml index 0483ba3..60e443a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ plain = "0.2.3" redox_dmi = "0.1.6" redox_hwio = { version = "0.1.6", default-features = false } redox_intelflash = "0.1.3" -redox_uefi_std = "0.1.12" +redox_uefi_std = "0.1.13" system76_ecflash = "0.1.3" [dependencies.system76_ectool] diff --git a/src/app/bios.rs b/src/app/bios.rs index d1d627a..4d4e538 100644 --- a/src/app/bios.rs +++ b/src/app/bios.rs @@ -4,15 +4,14 @@ use alloc::collections::BTreeMap; use alloc::string::String; use core::arch::asm; use core::char; +use core::ptr; use coreboot_fs::Rom; use ecflash::EcFlash; use intel_spi::{HsfStsCtl, Spi, SpiDev}; use plain::Plain; use std::fs::{find, load}; use std::prelude::*; -use std::ptr; use std::uefi::reset::ResetType; -use std::uefi::status::{Error, Result, Status}; use std::vars::{get_boot_item, get_boot_order, set_boot_item, set_boot_order}; use super::{ @@ -224,7 +223,7 @@ impl Component for BiosComponent { // Self::spi_unlock(); // } - let len = spi.len().map_err(|_| Error::DeviceError)?; + let len = spi.len().map_err(|_| Status::DEVICE_ERROR)?; Ok(data.len() == len) } else if self.capsule { Ok(true) @@ -290,11 +289,11 @@ impl Component for BiosComponent { } // Check ROM size - let len = spi.len().map_err(|_| Error::DeviceError)?; + let len = spi.len().map_err(|_| Status::DEVICE_ERROR)?; println!("SPI ROM: {} MB", len / (1024 * 1024)); if len != new.len() { println!("firmware.rom size invalid"); - return Err(Error::DeviceError); + return Err(Status::DEVICE_ERROR); } // Read current data @@ -306,7 +305,7 @@ impl Component for BiosComponent { let mut buf = [0; 4096]; let read = spi .read(data.len(), &mut buf) - .map_err(|_| Error::DeviceError)?; + .map_err(|_| Status::DEVICE_ERROR)?; data.extend_from_slice(&buf[..read]); // Print output once per megabyte @@ -325,7 +324,7 @@ impl Component for BiosComponent { Ok(false) => (), Err(err) => { println!("Ethernet: failed to copy: {}", err); - return Err(Error::DeviceError); + return Err(Status::DEVICE_ERROR); } } @@ -376,7 +375,7 @@ impl Component for BiosComponent { ); let new_slice = new .get_mut(new_offset..new_offset + new_size) - .ok_or(Error::DeviceError)?; + .ok_or(Status::DEVICE_ERROR)?; if let Some(area) = areas.get(area_name) { let offset = area.offset as usize; @@ -387,7 +386,7 @@ impl Component for BiosComponent { new_offset, new_size / 1024 ); - let slice = data.get(offset..offset + size).ok_or(Error::DeviceError)?; + let slice = data.get(offset..offset + size).ok_or(Status::DEVICE_ERROR)?; if slice.len() == new_slice.len() { new_slice.copy_from_slice(slice); @@ -471,7 +470,7 @@ impl Component for BiosComponent { "\nverification failed as {:#x}: {:#x} != {:#x}", address, data[address], new[address] ); - return Err(Error::DeviceError); + return Err(Status::DEVICE_ERROR); } address += 1; } @@ -547,7 +546,7 @@ impl Component for BiosComponent { if status != 0 { println!("{} Flash Error: {}", self.name(), status); - return Err(Error::DeviceError); + return Err(Status::DEVICE_ERROR); } } diff --git a/src/app/component.rs b/src/app/component.rs index be65541..6a611c4 100644 --- a/src/app/component.rs +++ b/src/app/component.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only -use std::uefi::status::Result; +use std::prelude::*; pub trait Component { fn name(&self) -> &str; diff --git a/src/app/ec.rs b/src/app/ec.rs index 3789c0b..e789066 100644 --- a/src/app/ec.rs +++ b/src/app/ec.rs @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-only -use core::ops::{ControlFlow, Try}; use ecflash::{Ec, EcFile, EcFlash}; use ectool::{timeout, Access, AccessLpcDirect, Firmware, SecurityState, Spi, SpiRom, SpiTarget, Timeout}; use plain::Plain; @@ -8,14 +7,13 @@ use std::prelude::*; use std::uefi::{ self, reset::ResetType, - status::{Error, Result, Status}, }; +use core::cell::Cell; +use core::ptr; +use core::str; use std::{ - cell::Cell, ffi::wstr, fs::{find, load}, - ptr, - str, }; use super::{pci_read, shell, Component, EC2ROM, ECROM, ECTAG, FIRMWAREDIR, FIRMWARENSH, sideband::Sideband}; @@ -745,7 +743,7 @@ impl Component for EcComponent { Ok(()) } else { println!("{} Flash Error: {}", self.name(), status); - Err(Error::DeviceError) + Err(Status::DEVICE_ERROR) } }, EcKind::System76(_ec, _pmc) => { @@ -757,7 +755,7 @@ impl Component for EcComponent { Ok(()) => Ok(()), Err(err) => { println!("{} Flash Error: {:X?}", self.name(), err); - Err(Error::DeviceError) + Err(Status::DEVICE_ERROR) } } } @@ -769,13 +767,13 @@ impl Component for EcComponent { Ok(()) => Ok(()), Err(err) => { println!("{} Flash Error: {:X?}", self.name(), err); - Err(Error::DeviceError) + Err(Status::DEVICE_ERROR) } } } EcKind::Unknown => { println!("{} Failed to flash EcKind::Unknown", self.name()); - Err(Error::DeviceError) + Err(Status::DEVICE_ERROR) } }; @@ -784,7 +782,7 @@ impl Component for EcComponent { Ok((_, firmware_dir)) => { //Try to create tag file without running shell let filename = wstr(ECTAG); - let mut file = std::ptr::null_mut::(); + let mut file = ptr::null_mut::(); match (firmware_dir.0.Open)( firmware_dir.0, &mut file, @@ -794,16 +792,15 @@ impl Component for EcComponent { | uefi::fs::FILE_MODE_WRITE, 0, ) - .branch() { - ControlFlow::Continue(_) => { + Status::SUCCESS => { unsafe { let _ = ((*file).Close)(&mut *file); } println!("EC tag: created successfully"); } - ControlFlow::Break(err) => { - println!("EC tag: failed to create {}: {:?}", ECTAG, err); + err => { + println!("EC tag: failed to create {}: {}", ECTAG, err); } } } @@ -836,9 +833,9 @@ fn memory_kind() -> Result { if let Ok(info) = dmi::MemoryDevice::from_bytes(&table.data) { return Ok(info.memory_kind); } else { - return Err(Error::DeviceError); + return Err(Status::DEVICE_ERROR); } } - Err(Error::DeviceError) + Err(Status::DEVICE_ERROR) } diff --git a/src/app/mod.rs b/src/app/mod.rs index 5fa2bc4..4b24da8 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,7 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-only -use core::ops::{ControlFlow, Try}; -use core::prelude::v1::derive; use core::{char, mem, ptr}; use orbclient::{Color, Renderer}; use std::exec::exec_path; @@ -9,9 +7,7 @@ use std::ffi::{nstr, wstr}; use std::fs::{find, load}; use std::prelude::*; use std::proto::Protocol; -use std::uefi::guid; use std::uefi::reset::ResetType; -use std::uefi::status::{Error, Result, Status}; use std::vars::{ get_boot_current, get_boot_item, get_boot_next, get_boot_order, set_boot_item, set_boot_next, set_boot_order, @@ -65,7 +61,7 @@ enum ValidateKind { Found, Mismatch, NotFound, - Error(Error), + Error(Status), } fn components_validations() -> (Vec>, Vec) { @@ -91,7 +87,7 @@ fn components_validations() -> (Vec>, Vec) { } } Err(err) => { - if err == Error::NotFound || err == Error::InvalidParameter { + if err == Status::NOT_FOUND || err == Status::INVALID_PARAMETER { ValidateKind::NotFound } else { ValidateKind::Error(err) @@ -130,15 +126,15 @@ fn reset_dmi() -> Result<()> { let mut vars = vec![]; let mut name = [0; 1024]; - let mut guid = guid::NULL_GUID; + let mut guid = Guid::NULL; loop { let mut size = 1024; let status = (uefi.RuntimeServices.GetNextVariableName)(&mut size, name.as_mut_ptr(), &mut guid); - if let ControlFlow::Break(err) = status.branch() { - match err { - Error::NotFound => break, - _ => return Err(err), + if !status.is_success() { + match status { + Status::NOT_FOUND => break, + _ => return Err(status), } } let name_str = nstr(name.as_mut_ptr()); @@ -154,16 +150,16 @@ fn reset_dmi() -> Result<()> { let mut attributes = 0; let mut data = [0; 65536]; let mut data_size = data.len(); - (uefi.RuntimeServices.GetVariable)( + Result::from((uefi.RuntimeServices.GetVariable)( wname.as_ptr(), &guid, &mut attributes, &mut data_size, data.as_mut_ptr(), - )?; + ))?; let empty = []; - (uefi.RuntimeServices.SetVariable)(wname.as_ptr(), &guid, attributes, 0, empty.as_ptr())?; + Result::from((uefi.RuntimeServices.SetVariable)(wname.as_ptr(), &guid, attributes, 0, empty.as_ptr()))?; } Ok(()) @@ -228,16 +224,15 @@ fn inner() -> Result<()> { } else { let c = if let Ok((_, ectag)) = find(ECTAG) { // Attempt to remove EC tag - match (ectag.0.Delete)(ectag.0).branch() { - ControlFlow::Continue(_) => { - println!("EC tag: deleted successfully"); + let status = (ectag.0.Delete)(ectag.0); + // XXX: Match previous behavior, which ignored warnings. + if !status.is_error() { + println!("EC tag: deleted successfully"); - // Have to prevent Close from being called after Delete - mem::forget(ectag); - } - ControlFlow::Break(err) => { - println!("EC tag: failed to delete: {:?}", err); - } + // Have to prevent Close from being called after Delete + mem::forget(ectag); + } else { + println!("EC tag: failed to delete: {}", status); } // Skip enter if system76 ec flashing already occured @@ -280,7 +275,7 @@ fn inner() -> Result<()> { Ok(()) => (), Err(err) => { println!("Failed to unlock firmware: {:?}", err); - return Err(Error::DeviceError); + return Err(Status::DEVICE_ERROR); } }, // Assume EC is unlocked if not running System76 EC @@ -373,7 +368,7 @@ pub fn main() -> Result<()> { for i in 0..output.0.Mode.MaxMode { let mut mode_ptr = ::core::ptr::null_mut(); let mut mode_size = 0; - (output.0.QueryMode)(output.0, i, &mut mode_size, &mut mode_ptr)?; + Result::from((output.0.QueryMode)(output.0, i, &mut mode_size, &mut mode_ptr))?; let mode = unsafe { &mut *mode_ptr }; let w = mode.HorizontalResolution; diff --git a/src/app/pci.rs b/src/app/pci.rs index 33a5266..2616f79 100644 --- a/src/app/pci.rs +++ b/src/app/pci.rs @@ -95,7 +95,7 @@ pub fn pci_mcfg() -> Option<&'static [u8]> { None } -pub fn pci_read(bus: u8, dev: u8, func: u8, offset: u8) -> Result { +pub fn pci_read(bus: u8, dev: u8, func: u8, offset: u8) -> core::result::Result { if dev > 0x1f { return Err(format!("pci_read dev 0x{:x} is greater than 0x1f", dev)); } diff --git a/src/display.rs b/src/display.rs index 2793f0d..60e6bde 100644 --- a/src/display.rs +++ b/src/display.rs @@ -2,12 +2,11 @@ use core::arch::asm; use core::cell::Cell; -use core::ops::Try; use orbclient::{Color, Mode, Renderer}; use std::prelude::*; use std::proto::Protocol; use std::uefi::graphics::{GraphicsBltOp, GraphicsBltPixel, GraphicsOutput}; -use std::uefi::guid::{Guid, GRAPHICS_OUTPUT_PROTOCOL_GUID}; +use std::uefi::guid::GRAPHICS_OUTPUT_PROTOCOL_GUID; pub struct Output(pub &'static mut GraphicsOutput); @@ -55,7 +54,7 @@ impl Display { h as usize, 0, ); - status.branch().is_continue() + status.is_success() } pub fn scroll(&mut self, rows: usize, color: Color) { diff --git a/src/image/bmp.rs b/src/image/bmp.rs index 7071b5a..634e19d 100644 --- a/src/image/bmp.rs +++ b/src/image/bmp.rs @@ -4,7 +4,7 @@ use std::prelude::*; use super::Image; -pub fn parse(file_data: &[u8]) -> Result { +pub fn parse(file_data: &[u8]) -> core::result::Result { use orbclient::Color; let get = |i: usize| -> u8 { diff --git a/src/image/mod.rs b/src/image/mod.rs index 458f09b..0e43587 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -4,7 +4,6 @@ use std::prelude::*; use core::cell::Cell; use core::cmp; -use core::prelude::v1::derive; use orbclient::{Color, Mode, Renderer}; @@ -61,7 +60,7 @@ impl Image { } /// Create a new image from a boxed slice of colors - pub fn from_data(width: u32, height: u32, data: Box<[Color]>) -> Result { + pub fn from_data(width: u32, height: u32, data: Box<[Color]>) -> core::result::Result { if (width * height) as usize != data.len() { return Err( "not enough or too much data given compared to width and height".to_string(), diff --git a/src/io.rs b/src/io.rs index 6068b35..34fb0ed 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,21 +1,21 @@ // SPDX-License-Identifier: GPL-3.0-only use core::char; -use std::uefi::status; +use std::prelude::*; use std::uefi::text::TextInputKey; -pub fn wait_key() -> Result { +pub fn wait_key() -> Result { let uefi = std::system_table(); let mut index = 0; - (uefi.BootServices.WaitForEvent)(1, &uefi.ConsoleIn.WaitForKey, &mut index)?; + Result::from((uefi.BootServices.WaitForEvent)(1, &uefi.ConsoleIn.WaitForKey, &mut index))?; let mut input = TextInputKey { ScanCode: 0, UnicodeChar: 0, }; - (uefi.ConsoleIn.ReadKeyStroke)(uefi.ConsoleIn, &mut input)?; + Result::from((uefi.ConsoleIn.ReadKeyStroke)(uefi.ConsoleIn, &mut input))?; Ok(unsafe { char::from_u32_unchecked(input.UnicodeChar as u32) }) } diff --git a/src/key.rs b/src/key.rs index c51bb2c..021b966 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,20 +1,20 @@ // SPDX-License-Identifier: GPL-3.0-only -use std::uefi::status::Result; +use std::prelude::*; use std::uefi::text::TextInputKey; pub fn raw_key() -> Result { let uefi = std::system_table(); let mut index = 0; - (uefi.BootServices.WaitForEvent)(1, &uefi.ConsoleIn.WaitForKey, &mut index)?; + Result::from((uefi.BootServices.WaitForEvent)(1, &uefi.ConsoleIn.WaitForKey, &mut index))?; let mut key = TextInputKey { ScanCode: 0, UnicodeChar: 0, }; - (uefi.ConsoleIn.ReadKeyStroke)(uefi.ConsoleIn, &mut key)?; + Result::from((uefi.ConsoleIn.ReadKeyStroke)(uefi.ConsoleIn, &mut key))?; Ok(key) } diff --git a/src/main.rs b/src/main.rs index 20d73aa..63d40d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,6 @@ #![no_std] #![no_main] -#![feature(try_trait_v2)] -#![feature(control_flow_enum)] #![allow(clippy::collapsible_if)] #![allow(clippy::many_single_char_names)] #![allow(clippy::missing_safety_doc)] @@ -17,11 +15,9 @@ extern crate uefi_std as std; use std::prelude::*; -use core::ops::{ControlFlow, Try}; use core::ptr; use std::uefi; use std::uefi::reset::ResetType; -use std::uefi::status::{Result, Status}; mod app; mod display; @@ -39,10 +35,7 @@ fn set_max_mode(output: &uefi::text::TextOutput) -> Result<()> { for i in 0..output.Mode.MaxMode as usize { let mut w = 0; let mut h = 0; - if (output.QueryMode)(output, i, &mut w, &mut h) - .branch() - .is_continue() - { + if (output.QueryMode)(output, i, &mut w, &mut h).is_success() { if w >= max_w && h >= max_h { max_i = Some(i); max_w = w; @@ -52,7 +45,7 @@ fn set_max_mode(output: &uefi::text::TextOutput) -> Result<()> { } if let Some(i) = max_i { - (output.SetMode)(output, i)?; + Result::from((output.SetMode)(output, i))?; } Ok(()) @@ -64,7 +57,7 @@ pub extern "C" fn main() -> Status { let _ = (uefi.BootServices.SetWatchdogTimer)(0, 0, 0, ptr::null()); - if let ControlFlow::Break(err) = set_max_mode(uefi.ConsoleOut).branch() { + if let Err(err) = set_max_mode(uefi.ConsoleOut) { println!("Failed to set max mode: {:?}", err); } diff --git a/src/text.rs b/src/text.rs index 024b174..5344f05 100644 --- a/src/text.rs +++ b/src/text.rs @@ -7,9 +7,7 @@ use std::prelude::*; use std::proto::Protocol; use std::uefi::boot::InterfaceType; use std::uefi::guid::SIMPLE_TEXT_OUTPUT_GUID; -use std::uefi::status::{Result, Status}; use std::uefi::text::TextOutputMode; -use std::uefi::Handle; use crate::display::{Display, Output, ScaledDisplay}; @@ -242,12 +240,12 @@ impl<'a> TextDisplay<'a> { let stdout = self as *mut _; let mut stdout_handle = Handle(0); - (uefi.BootServices.InstallProtocolInterface)( + Result::from((uefi.BootServices.InstallProtocolInterface)( &mut stdout_handle, &SIMPLE_TEXT_OUTPUT_GUID, InterfaceType::Native, stdout as usize, - )?; + ))?; let old_stdout_handle = uefi.ConsoleOutHandle; let old_stdout = uefi.ConsoleOut as *mut _;