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 <[email protected]>
  • Loading branch information
crawfxrd committed Jun 10, 2024
1 parent 33bf2f3 commit a118480
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 82 deletions.
21 changes: 9 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 @@ -16,7 +16,7 @@ orbfont = { version = "0.1.12", default-features = false, features = ["no-std"]
plain = "0.2.3"
redox_dmi = "0.1.6"
redox_hwio = { version = "0.1.6", default-features = false }
redox_uefi_std = "0.1.11"
redox_uefi_std = { git = "https://gitlab.redox-os.org/redox-os/uefi.git" }
spin = "0.9.4"

[dependencies.system76_ectool]
Expand Down
6 changes: 3 additions & 3 deletions src/display.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-only

use core::cell::Cell;
use core::ops::Try;
use orbclient::{Color, Mode, Renderer};
use std::prelude::*;
use std::proto::Protocol;
use std::uefi::graphics::{GraphicsOutput, GraphicsBltOp, GraphicsBltPixel};
use std::uefi::guid::{Guid, GRAPHICS_OUTPUT_PROTOCOL_GUID};
use std::uefi::guid::GRAPHICS_OUTPUT_PROTOCOL_GUID;

pub struct Output(pub &'static mut GraphicsOutput);

Expand Down Expand Up @@ -53,7 +53,7 @@ impl Display {
h as usize,
0
);
status.branch().is_continue()
status.is_success()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/dump_hii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use hwio::{Io, Pio};
use std::{char, mem, ptr, str};
use std::ops::Try;
use std::proto::Protocol;
use std::prelude::*;
use std::uefi::hii::database::HiiHandle;
use std::uefi::hii::ifr::{IfrOpCode, IfrOpHeader, IfrForm, IfrAction};
use std::uefi::hii::package::{HiiPackageHeader, HiiPackageKind, HiiPackageListHeader, HiiStringPackageHeader};
use std::uefi::hii::sibt::{SibtHeader, SibtKind, SibtEnd, SibtSkip2, SibtStringUcs2, SibtStringsUcs2};
use std::uefi::status::{Error, Result};

use crate::hii;

Expand Down
29 changes: 11 additions & 18 deletions src/fde.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
// SPDX-License-Identifier: GPL-3.0-only

use core::prelude::v1::derive;
use core::ops::FromResidual;
use orbclient::{Color, Renderer};
use orbfont::Text;
use std::{char, cmp, ffi, mem, ptr, slice};
use std::ops::Try;
use core::{char, cmp, mem, ptr, slice};
use std::prelude::*;
use std::proto::Protocol;
use std::uefi::Event;
use std::uefi::guid::Guid;
use std::ffi;
use std::uefi::hii::{AnimationId, ImageId, StringId};
use std::uefi::hii::database::HiiHandle;
use std::uefi::hii::ifr::{
HiiValue,
IfrOpCode, IfrOpHeader, IfrStatementHeader, IfrTypeValueEnum,
IfrAction, IfrCheckbox, IfrNumeric, IfrOneOf, IfrOneOfOption, IfrOrderedList, IfrRef, IfrSubtitle
};
use std::uefi::status::{Error, Result, Status};
use std::uefi::text::TextInputKey;

use crate::display::{Display, Output};
use crate::key::{raw_key, Key};
use crate::ui::Ui;

// TODO: Move to uefi library {
pub const HII_STRING_PROTOCOL_GUID: Guid = Guid(0xfd96974, 0x23aa, 0x4cdc, [0xb9, 0xcb, 0x98, 0xd1, 0x77, 0x50, 0x32, 0x2a]);
pub const HII_STRING_PROTOCOL_GUID: Guid = guid!("0fd96974-23aa-4cdc-b9cb-98d17750322a");

#[repr(C)]
pub struct HiiStringProtocol {
Expand All @@ -47,15 +43,15 @@ impl HiiStringProtocol {
pub fn string(&self, PackageList: HiiHandle, StringId: StringId) -> Result<String> {
let mut data = vec![0u16; 4096];
let mut len = data.len();
(self.GetString)(
Result::from((self.GetString)(
self,
b"en-US\0".as_ptr(),
PackageList,
StringId,
data.as_mut_ptr(),
&mut len,
0
)?;
))?;
data.truncate(len);

let mut string = String::new();
Expand Down Expand Up @@ -354,7 +350,7 @@ fn wait_for_events(form: &Form) -> Result<EventType> {
events.push(form.FormRefreshEvent);
}

(uefi.BootServices.WaitForEvent)(events.len(), events.as_mut_ptr(), &mut index)?;
Result::from((uefi.BootServices.WaitForEvent)(events.len(), events.as_mut_ptr(), &mut index))?;

if index == 0 {
Ok(EventType::Keyboard)
Expand Down Expand Up @@ -776,7 +772,7 @@ fn form_display_inner(form: &Form, user_input: &mut UserInput) -> Result<()> {
let raw_key = match raw_key(false) {
Ok(ok) => ok,
Err(err) => match err {
Error::NotReady => break 'input,
Status::NOT_READY => break 'input,
_ => return Err(err),
}
};
Expand Down Expand Up @@ -1030,10 +1026,7 @@ fn form_display_inner(form: &Form, user_input: &mut UserInput) -> Result<()> {
}

extern "win64" fn form_display(form: &Form, user_input: &mut UserInput) -> Status {
match form_display_inner(form, user_input) {
Ok(()) => Status::from_output(0),
Err(err) => Status::from_residual(err),
}
form_display_inner(form, user_input).into()
}

extern "win64" fn exit_display() {
Expand All @@ -1047,13 +1040,13 @@ extern "win64" fn confirm_data_change() -> usize {

impl Fde {
pub fn install() -> Result<()> {
let guid = Guid(0x9bbe29e9, 0xfda1, 0x41ec, [0xad, 0x52, 0x45, 0x22, 0x13, 0x74, 0x2d, 0x2e]);
let guid = guid!("9bbe29e9-fda1-41ec-ad52-452213742d2e");

let uefi = unsafe { std::system_table_mut() };

let current = unsafe {
let mut interface = 0;
(uefi.BootServices.LocateProtocol)(&guid, 0, &mut interface)?;
Result::from((uefi.BootServices.LocateProtocol)(&guid, 0, &mut interface))?;
&mut *(interface as *mut Fde)
};

Expand Down
3 changes: 2 additions & 1 deletion src/hii.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only

use std::proto::Protocol;
use std::prelude::*;
use std::uefi::hii::database::HiiDatabase;
use std::uefi::guid::{Guid, HII_DATABASE_GUID};
use std::uefi::guid::HII_DATABASE_GUID;

pub struct Database(pub &'static mut HiiDatabase);

Expand Down
4 changes: 3 additions & 1 deletion src/image/bmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

use super::Image;

pub fn parse(file_data: &[u8]) -> Result<Image, String> {
use std::prelude::*;

pub fn parse(file_data: &[u8]) -> core::result::Result<Image, String> {
use orbclient::Color;

let get = |i: usize| -> u8 {
Expand Down
6 changes: 4 additions & 2 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

use core::cell::Cell;
use core::cmp;
use core::prelude::v1::derive;
use core::default::Default;

use std::prelude::*;

use orbclient::{Color, Mode, Renderer};

Expand Down Expand Up @@ -51,7 +53,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<Self, String> {
pub fn from_data(width: u32, height: u32, data: Box<[Color]>) -> core::result::Result<Self, String> {
if (width * height) as usize != data.len() {
return Err("not enough or too much data given compared to width and height".to_string())
}
Expand Down
7 changes: 3 additions & 4 deletions src/key.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only

use core::char;
use core::prelude::v1::derive;
use std::uefi::status::Result;
use std::prelude::*;
use std::uefi::text::TextInputKey;

#[derive(Debug)]
Expand Down Expand Up @@ -79,15 +78,15 @@ pub fn raw_key(wait: bool) -> Result<TextInputKey> {

if wait {
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)
}
Expand Down
9 changes: 0 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@

#![no_std]
#![no_main]
#![feature(core_intrinsics)]
#![feature(prelude_import)]
#![feature(try_trait_v2)]
#![feature(control_flow_enum)]
#![allow(non_snake_case)]

#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate memoffset;
#[macro_use]
extern crate uefi_std as std;

#[allow(unused_imports)]
#[prelude_import]
use std::prelude::*;

use core::ptr;
use std::uefi::status::Status;

#[macro_use]
mod debug;
Expand Down
15 changes: 5 additions & 10 deletions src/rng.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
use std::{
proto::Protocol,
ptr,
};
use std::uefi::{
guid::Guid,
status::{Result, Status},
};
use core::ptr;
use std::proto::Protocol;
use std::prelude::*;

pub const RNG_PROTOCOL_GUID: Guid = Guid(0x3152bca5, 0xeade, 0x433d, [0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44]);

pub struct Rng(pub &'static mut RngProtocol);

impl Rng {
pub fn read(&self, buf: &mut [u8]) -> Result<()> {
(self.0.GetRNG)(
Result::from((self.0.GetRNG)(
self.0,
ptr::null(),
buf.len(),
buf.as_mut_ptr(),
)?;
))?;
Ok(())
}
}
Expand Down
21 changes: 9 additions & 12 deletions src/security.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use core::cell::Cell;
use core::cmp;
use core::ptr;

use ectool::{AccessLpcDirect, Ec, SecurityState, Timeout};
use orbclient::{Color, Renderer};
use std::{
cell::Cell,
cmp,
proto::Protocol,
ptr,
};
use std::prelude::*;
use std::proto::Protocol;
use std::uefi::{
Handle,
boot::InterfaceType,
guid::Guid,
reset::ResetType,
status::{Error, Result, Status},
};

use crate::display::{Display, Output};
Expand Down Expand Up @@ -228,7 +225,7 @@ fn confirm(display: &mut Display) -> Result<()> {
}
} else {
// Return error if cancel selected
return Err(Error::Aborted);
return Err(Status::ABORTED);
}
},
Key::Escape => {
Expand Down Expand Up @@ -341,12 +338,12 @@ pub fn install() -> Result<()> {
});
let protocol_ptr = Box::into_raw(protocol);
let mut handle = Handle(0);
(uefi.BootServices.InstallProtocolInterface)(
Result::from((uefi.BootServices.InstallProtocolInterface)(
&mut handle,
&SYSTEM76_SECURITY_PROTOCOL_GUID,
InterfaceType::Native,
protocol_ptr as usize
)?;
))?;

Ok(())
}
5 changes: 2 additions & 3 deletions src/serial.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only

use core::convert::TryInto;
use core::prelude::v1::derive;
use hwio::{Io, Pio, Mmio, ReadOnly};

bitflags! {
bitflags::bitflags! {
/// Interrupt enable flags
struct IntEnFlags: u8 {
const RECEIVED = 1;
Expand All @@ -15,7 +14,7 @@ bitflags! {
}
}

bitflags! {
bitflags::bitflags! {
/// Line status flags
struct LineStsFlags: u8 {
const INPUT_FULL = 1;
Expand Down
Loading

0 comments on commit a118480

Please sign in to comment.