Skip to content

Commit

Permalink
Update redox_uefi_std
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Crawford <tcrawford@system76.com>
  • Loading branch information
crawfxrd committed Jun 28, 2024
1 parent b6d10f7 commit 3657742
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 89 deletions.
27 changes: 15 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
21 changes: 10 additions & 11 deletions src/app/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/component.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
29 changes: 13 additions & 16 deletions src/app/ec.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// 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;
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};
Expand Down Expand Up @@ -744,7 +742,7 @@ impl Component for EcComponent {
Ok(())
} else {
println!("{} Flash Error: {}", self.name(), status);
Err(Error::DeviceError)
Err(Status::DEVICE_ERROR)
}
},
EcKind::System76(_ec, _pmc) => {
Expand All @@ -756,7 +754,7 @@ impl Component for EcComponent {
Ok(()) => Ok(()),
Err(err) => {
println!("{} Flash Error: {:X?}", self.name(), err);
Err(Error::DeviceError)
Err(Status::DEVICE_ERROR)
}
}
}
Expand All @@ -768,13 +766,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)
}
};

Expand All @@ -783,7 +781,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::<uefi::fs::File>();
let mut file = ptr::null_mut::<uefi::fs::File>();
match (firmware_dir.0.Open)(
firmware_dir.0,
&mut file,
Expand All @@ -793,16 +791,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);
}
}
}
Expand Down Expand Up @@ -835,9 +832,9 @@ fn memory_kind() -> Result<u8> {
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)
}
36 changes: 16 additions & 20 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// 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;
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,
Expand Down Expand Up @@ -65,7 +61,7 @@ enum ValidateKind {
Found,
Mismatch,
NotFound,
Error(Error),
Error(Status),
}

fn components_validations() -> (Vec<Box<dyn Component>>, Vec<ValidateKind>) {
Expand All @@ -91,7 +87,7 @@ fn components_validations() -> (Vec<Box<dyn Component>>, Vec<ValidateKind>) {
}
}
Err(err) => {
if err == Error::NotFound || err == Error::InvalidParameter {
if err == Status::NOT_FOUND || err == Status::INVALID_PARAMETER {
ValidateKind::NotFound
} else {
ValidateKind::Error(err)
Expand Down Expand Up @@ -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());
Expand All @@ -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(())
Expand Down Expand Up @@ -228,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);
}
}

Expand Down Expand Up @@ -280,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
Expand Down Expand Up @@ -373,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;
Expand Down
Loading

0 comments on commit 3657742

Please sign in to comment.