Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate CMOS checksum after flashing #83

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/app/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use std::vars::{get_boot_item, get_boot_order, set_boot_item, set_boot_order};

use super::{
pci_mcfg, shell, Component, UefiMapper, FIRMWARECAP, FIRMWAREDIR, FIRMWARENSH, FIRMWAREROM,
H2OFFT, IFLASHV, UEFIFLASH,
cmos, pci_mcfg, shell, Component, UefiMapper, FIRMWARECAP, FIRMWAREDIR, FIRMWARENSH,
FIRMWAREROM, H2OFFT, IFLASHV, UEFIFLASH,
};

fn copy_region(
Expand All @@ -37,7 +37,7 @@
if base < limit && limit < old_data.len() {
&old_data[base..limit + 1]
} else {
return Err(format!("old region {:#X}:{:#X} is invalid", base, limit));

Check warning on line 40 in src/app/bios.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/app/bios.rs:40:28 | 40 | return Err(format!("old region {:#X}:{:#X} is invalid", base, limit)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args = note: `#[warn(clippy::uninlined_format_args)]` on by default help: change this to | 40 - return Err(format!("old region {:#X}:{:#X} is invalid", base, limit)); 40 + return Err(format!("old region {base:#X}:{limit:#X} is invalid")); |
}
}
None => return Err("missing old region".to_string()),
Expand All @@ -48,7 +48,7 @@
if base < limit && limit < new_data.len() {
&mut new_data[base..limit + 1]
} else {
return Err(format!("new region {:#X}:{:#X} is invalid", base, limit));

Check warning on line 51 in src/app/bios.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/app/bios.rs:51:28 | 51 | return Err(format!("new region {:#X}:{:#X} is invalid", base, limit)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 51 - return Err(format!("new region {:#X}:{:#X} is invalid", base, limit)); 51 + return Err(format!("new region {base:#X}:{limit:#X} is invalid")); |
}
}
None => return Err("missing new region".to_string()),
Expand Down Expand Up @@ -512,6 +512,13 @@
}
println!();
}

// Invalidate the 2-byte CMOS checksum to force writing the option defaults.
let mut cmos = cmos::Cmos::default();
let old_hi = cmos.read(123);
let old_lo = cmos.read(124);
cmos.write(123, !old_hi);
cmos.write(124, !old_lo);
} else {
find(FIRMWARENSH)?;

Expand All @@ -531,7 +538,7 @@
println!("Failed to preserve boot order");
}

let cmd = format!("{} {} bios flash", FIRMWARENSH, FIRMWAREDIR);

Check warning on line 541 in src/app/bios.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/app/bios.rs:541:23 | 541 | let cmd = format!("{} {} bios flash", FIRMWARENSH, FIRMWAREDIR); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 541 - let cmd = format!("{} {} bios flash", FIRMWARENSH, FIRMWAREDIR); 541 + let cmd = format!("{FIRMWARENSH} {FIRMWAREDIR} bios flash"); |
let status = shell(&cmd)?;

#[allow(clippy::single_match)]
Expand Down
33 changes: 33 additions & 0 deletions src/app/cmos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-3.0-only

use hwio::{Io, Pio};

pub struct Cmos {
port: Pio<u8>,
data: Pio<u8>,
}

impl Cmos {
pub fn new(port: u16) -> Self {
Self {
port: Pio::<u8>::new(port),
data: Pio::<u8>::new(port + 1),
}
}

pub fn read(&mut self, addr: u8) -> u8 {
self.port.write(addr);
self.data.read()
}

pub fn write(&mut self, addr: u8, data: u8) {
self.port.write(addr);
self.data.write(data);
}
}

impl Default for Cmos {
fn default() -> Self {
Self::new(0x70)
}
}
1 change: 1 addition & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub use self::mapper::UefiMapper;
pub use self::pci::{pci_mcfg, pci_read};

mod bios;
mod cmos;
mod component;
mod ec;
mod mapper;
Expand Down
Loading