diff --git a/Cargo.lock b/Cargo.lock index 1a8bd0a..48e6ef2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" @@ -43,9 +43,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libredox" @@ -96,7 +96,7 @@ checksum = "7d8e51d17548d82fa194ca49c6adf81fce4a45bbddfdd7d35f68725cec1943f5" dependencies = [ "bitflags 1.3.2", "plain", - "redox_uefi", + "redox_uefi 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -114,22 +114,25 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad1ef8d2afbe5adfc257e0847f360d0f175e7012c4fa984a284966b54ad5834d" +[[package]] +name = "redox_uefi" +version = "0.1.12" +source = "git+https://gitlab.redox-os.org/redox-os/uefi.git#be546ac6d164d30504214cb33ef338c64f2ac992" + [[package]] name = "redox_uefi_alloc" version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12fe0357fd0ecc7c7de510c9add51a52a9268c3fa5890f9c8dbef890e4b2d1f6" +source = "git+https://gitlab.redox-os.org/redox-os/uefi.git#be546ac6d164d30504214cb33ef338c64f2ac992" dependencies = [ - "redox_uefi", + "redox_uefi 0.1.12 (git+https://gitlab.redox-os.org/redox-os/uefi.git)", ] [[package]] name = "redox_uefi_std" version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a19dfc2a64c4a152fff1819c6ce74460c322a46da9c812ffaa1282260c19ec2" +source = "git+https://gitlab.redox-os.org/redox-os/uefi.git#be546ac6d164d30504214cb33ef338c64f2ac992" dependencies = [ - "redox_uefi", + "redox_uefi 0.1.12 (git+https://gitlab.redox-os.org/redox-os/uefi.git)", "redox_uefi_alloc", ] @@ -142,7 +145,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#fc3bad29a2a31555bccaaacb6af6d20b7bb1b7f6" dependencies = [ "downcast-rs", "redox_hwio", diff --git a/Cargo.toml b/Cargo.toml index 0483ba3..43b1f37 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 = { git = "https://gitlab.redox-os.org/redox-os/uefi.git" } 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 2894022..aec5ef2 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}; @@ -741,7 +739,7 @@ impl Component for EcComponent { Ok(()) } else { println!("{} Flash Error: {}", self.name(), status); - Err(Error::DeviceError) + Err(Status::DEVICE_ERROR) } }, EcKind::System76(_ec, _pmc) => { @@ -753,7 +751,7 @@ impl Component for EcComponent { Ok(()) => Ok(()), Err(err) => { println!("{} Flash Error: {:X?}", self.name(), err); - Err(Error::DeviceError) + Err(Status::DEVICE_ERROR) } } } @@ -765,13 +763,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) } }; @@ -780,7 +778,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, @@ -790,16 +788,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); } } } @@ -832,9 +829,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 3ba98e4..458ac5f 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; @@ -11,7 +9,6 @@ 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, @@ -64,7 +61,7 @@ enum ValidateKind { Found, Mismatch, NotFound, - Error(Error), + Error(Status), } fn components_validations() -> (Vec>, Vec) { @@ -90,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) @@ -134,10 +131,10 @@ fn reset_dmi() -> Result<()> { 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()); @@ -153,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(()) @@ -227,15 +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(_) => { + match (ectag.0.Delete)(ectag.0) { + Status::SUCCESS => { 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); + err => { + println!("EC tag: failed to delete: {}", err); } } @@ -279,7 +276,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 @@ -372,7 +369,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..2d486a4 100644 --- a/src/display.rs +++ b/src/display.rs @@ -2,7 +2,6 @@ use core::arch::asm; use core::cell::Cell; -use core::ops::Try; use orbclient::{Color, Mode, Renderer}; use std::prelude::*; use std::proto::Protocol; @@ -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 _;