Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Crawford <tcrawford@system76.com>
  • Loading branch information
crawfxrd committed Dec 11, 2024
1 parent 6c19a28 commit 2325f02
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 43 deletions.
8 changes: 6 additions & 2 deletions src/app/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ impl Component for BiosComponent {
new_offset,
new_size / 1024
);
let slice = data.get(offset..offset + size).ok_or(Status::DEVICE_ERROR)?;
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 @@ -487,7 +489,9 @@ impl Component for BiosComponent {

// Have coreboot reset the option table to the defaults.
let mut cmos_options = cmos::CmosOptionTable::new();
unsafe { cmos_options.invalidate_checksum(); }
unsafe {
cmos_options.invalidate_checksum();
}
} else {
find(FIRMWARENSH)?;

Expand Down
66 changes: 34 additions & 32 deletions src/app/ec.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
// SPDX-License-Identifier: GPL-3.0-only

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,
};
use core::cell::Cell;
use core::ptr;
use core::str;
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};
use std::{
ffi::wstr,
fs::{find, load},
};

use super::{pci_read, shell, Component, EC2ROM, ECROM, ECTAG, FIRMWAREDIR, FIRMWARENSH, sideband::Sideband};
use super::{
pci_read, shell, sideband::Sideband, Component, EC2ROM, ECROM, ECTAG, FIRMWAREDIR, FIRMWARENSH,
};

pub struct UefiTimeout {
duration: u64,
Expand Down Expand Up @@ -47,7 +48,10 @@ impl Timeout for UefiTimeout {

pub enum EcKind {
Pang(ectool::Pmc<UefiTimeout>, String),
System76(ectool::Ec<AccessLpcDirect<UefiTimeout>>, ectool::Pmc<UefiTimeout>),
System76(
ectool::Ec<AccessLpcDirect<UefiTimeout>>,
ectool::Pmc<UefiTimeout>,
),
Legacy(EcFlash),
Unknown,
}
Expand All @@ -74,21 +78,21 @@ impl EcKind {
}
}

if system_version == "pang12" || system_version == "pang13" || system_version == "pang14" ||
system_version == "pang15" {
if system_version == "pang12"
|| system_version == "pang13"
|| system_version == "pang14"
|| system_version == "pang15"
{
return EcKind::Pang(
ectool::Pmc::new(0x62, UefiTimeout::new(100_000)),
system_version
system_version,
);
}
}

if let Ok(access) = AccessLpcDirect::new(UefiTimeout::new(100_000)) {
if let Ok(ec) = ectool::Ec::new(access) {
return EcKind::System76(
ec,
ectool::Pmc::new(0x62, UefiTimeout::new(100_000))
);
return EcKind::System76(ec, ectool::Pmc::new(0x62, UefiTimeout::new(100_000)));
}
}

Expand All @@ -104,15 +108,15 @@ impl EcKind {
EcKind::Pang(ref mut pmc, _system_version) => {
let ecwr = pmc.acpi_read(0x80).unwrap_or(0);
(ecwr & 0x01) == 0x01
},
}
EcKind::System76(_ec, ref mut pmc) => {
let adp = pmc.acpi_read(0x10).unwrap_or(0);
(adp & 0x01) == 0x01
},
}
EcKind::Legacy(ref mut ec) => {
let adp = ec.get_param(0x10).unwrap_or(0);
(adp & 0x01) == 0x01
},
}
EcKind::Unknown => true,
}
}
Expand All @@ -121,7 +125,7 @@ impl EcKind {
match self {
EcKind::Pang(_pmc, system_version) => {
return system_version.clone();
},
}
EcKind::System76(ec, _pmc) => {
let data_size = ec.access().data_size();
let mut data = vec![0; data_size];
Expand Down Expand Up @@ -149,7 +153,7 @@ impl EcKind {
Err(err) => {
println!("Failed to read build time: {:?}", err);
return String::new();
},
}
}
}

Expand All @@ -160,16 +164,15 @@ impl EcKind {
Err(err) => {
println!("Failed to read build date: {:?}", err);
return String::new();
},
}
}
}

return format!(
"20{:02}/{:02}/{:02}_{:02}:{:02}:{:02}",
ymd[0], ymd[1], ymd[2],
hms[0], hms[1], hms[2]
ymd[0], ymd[1], ymd[2], hms[0], hms[1], hms[2]
);
},
}
EcKind::System76(ec, _pmc) => {
let data_size = ec.access().data_size();
let mut data = vec![0; data_size];
Expand Down Expand Up @@ -247,7 +250,7 @@ impl EcComponent {
} else {
"system76/lemp13-b".to_string()
}
},
}
"N130ZU" => "system76/galp3-c".to_string(),
"N140CU" => "system76/galp4".to_string(),
"N150ZU" => "system76/darp5".to_string(),
Expand Down Expand Up @@ -288,7 +291,7 @@ impl EcComponent {
"system76/darp10".to_string()
}
}
},
}
"NV40Mx" | "NV40Mx-DV" | "NV40MJ" => "system76/galp5".to_string(),
"NV4xPZ" => "system76/galp6".to_string(),
"NV40RZ" => "system76/galp7".to_string(),
Expand Down Expand Up @@ -489,7 +492,7 @@ pub unsafe fn security_unlock() -> core::result::Result<(), ectool::Error> {
ResetType::Shutdown,
Status(0),
0,
ptr::null()
ptr::null(),
);
}
},
Expand Down Expand Up @@ -746,7 +749,7 @@ impl Component for EcComponent {
println!("{} Flash Error: {}", self.name(), status);
Err(Status::DEVICE_ERROR)
}
},
}
EcKind::System76(_ec, _pmc) => {
// System76 EC requires reset to load new firmware
requires_reset = true;
Expand Down Expand Up @@ -792,8 +795,7 @@ impl Component for EcComponent {
| uefi::fs::FILE_MODE_READ
| uefi::fs::FILE_MODE_WRITE,
0,
)
{
) {
Status::SUCCESS => {
unsafe {
let _ = ((*file).Close)(&mut *file);
Expand Down
23 changes: 18 additions & 5 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::prelude::*;
use std::proto::Protocol;
use std::uefi::reset::ResetType;
use std::vars::{
get_boot_current, get_boot_item, get_boot_next, get_boot_order,
set_boot_item, set_boot_next, set_boot_order,
get_boot_current, get_boot_item, get_boot_next, get_boot_order, set_boot_item, set_boot_next,
set_boot_order,
};

use crate::display::{Display, Output, ScaledDisplay};
Expand Down Expand Up @@ -159,7 +159,13 @@ fn reset_dmi() -> Result<()> {
))?;

let empty = [];
Result::from((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 @@ -278,7 +284,9 @@ fn inner() -> Result<()> {
// XXX: Probably better to check for HECI device.
if cmos_options.me_state() {
println!("Disabling CSME for writing SPI flash");
unsafe { cmos_options.set_me_state(false); }
unsafe {
cmos_options.set_me_state(false);
}

println!("System will reboot in 5 seconds");
let _ = (std::system_table().BootServices.Stall)(5_000_000);
Expand Down Expand Up @@ -396,7 +404,12 @@ 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;
Result::from((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
4 changes: 3 additions & 1 deletion src/app/sideband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub struct Sideband {
impl Sideband {
pub unsafe fn new(sbreg_phys: usize) -> Self {
// On UEFI, physical memory is identity mapped
Self { addr: sbreg_phys as u64 }
Self {
addr: sbreg_phys as u64,
}
}

#[must_use]
Expand Down
6 changes: 5 additions & 1 deletion src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ impl Image {
}

/// Create a new image from a boxed slice of colors
pub fn from_data(width: u32, height: u32, data: Box<[Color]>) -> core::result::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
6 changes: 5 additions & 1 deletion src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ pub fn wait_key() -> Result<char> {
let uefi = std::system_table();

let mut index = 0;
Result::from((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,
Expand Down
6 changes: 5 additions & 1 deletion src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ pub fn raw_key() -> Result<TextInputKey> {
let uefi = std::system_table();

let mut index = 0;
Result::from((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,
Expand Down

0 comments on commit 2325f02

Please sign in to comment.