From 42019d932eec2f7f9f3c46af232fbbdd77100e21 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Fri, 29 Nov 2024 21:22:13 -0700 Subject: [PATCH 1/3] Remove unused binutils file Signed-off-by: Tim Crawford --- binutils.sha384 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 binutils.sha384 diff --git a/binutils.sha384 b/binutils.sha384 deleted file mode 100644 index 29f5a02..0000000 --- a/binutils.sha384 +++ /dev/null @@ -1 +0,0 @@ -de6d9c24b86e8e3c2eaecea7d02505965760f92481d35f8322b48bd11f6cd343212328da5fc46a5bb883a7e55b90040c *prefix/binutils-2.28.1.tar.xz.partial From aeef2a12bcdc3ec54f71a551c3d7b259c4137349 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Fri, 29 Nov 2024 21:42:01 -0700 Subject: [PATCH 2/3] Remove unused feature, module, deps Fixes: ef237e7bf85c ("Remove debug logging") Signed-off-by: Tim Crawford --- Cargo.lock | 57 +++---------------------------------------------- Cargo.toml | 7 ------ src/coreboot.rs | 35 ------------------------------ src/main.rs | 3 --- 4 files changed, 3 insertions(+), 99 deletions(-) delete mode 100644 src/coreboot.rs diff --git a/Cargo.lock b/Cargo.lock index 4dc75f1..fd63615 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,11 +23,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -[[package]] -name = "coreboot-table" -version = "0.1.6" -source = "git+https://gitlab.redox-os.org/redox-os/coreboot-table.git#e90d498fd419445acc7739676ac659b00f29f349" - [[package]] name = "downcast-rs" version = "1.2.1" @@ -36,9 +31,9 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "libc" -version = "0.2.162" +version = "0.2.167" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" +checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" [[package]] name = "libm" @@ -57,16 +52,6 @@ dependencies = [ "redox_syscall", ] -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memoffset" version = "0.9.1" @@ -114,21 +99,6 @@ dependencies = [ "ttf-parser", ] -[[package]] -name = "plain" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" - -[[package]] -name = "redox_dmi" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216218af5d41f90d4ed3fd7e136d359fb8ed567f641bb0c61c0e4960c7f7789c" -dependencies = [ - "plain", -] - [[package]] name = "redox_hwio" version = "0.1.6" @@ -180,25 +150,10 @@ dependencies = [ "owned_ttf_parser", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "system76_ectool" version = "0.3.8" -source = "git+https://github.com/system76/ec.git#3d8204c3f40b4de1e3b94f2c1aaca5f29a80122e" +source = "git+https://github.com/system76/ec.git#85da2d2d0c83a700a714bf9f1cf5319755c9192a" dependencies = [ "downcast-rs", "redox_hwio", @@ -208,16 +163,10 @@ dependencies = [ name = "system76_firmware_setup" version = "1.0.0" dependencies = [ - "bitflags", - "coreboot-table", "memoffset", "orbclient", "orbfont", - "plain", - "redox_dmi", - "redox_hwio", "redox_uefi_std", - "spin", "system76_ectool", ] diff --git a/Cargo.toml b/Cargo.toml index 936bfa2..156dc0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,16 +8,10 @@ license = "GPL-3.0-only" lto = true [dependencies] -bitflags = "2.5.0" -coreboot-table = { git = "https://gitlab.redox-os.org/redox-os/coreboot-table.git" } memoffset = "0.9" orbclient = { version = "0.3.46", default-features = false } 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.13" -spin = "0.9.4" [dependencies.system76_ectool] git = "https://github.com/system76/ec.git" @@ -26,4 +20,3 @@ features = ["redox_hwio"] [features] default = [] -debug = [] diff --git a/src/coreboot.rs b/src/coreboot.rs deleted file mode 100644 index 4575fcd..0000000 --- a/src/coreboot.rs +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -use coreboot_table::{Mapper, PhysicalAddress, Serial, Table, VirtualAddress}; -use spin::Mutex; - -pub struct PhysicalMapper; - -impl Mapper for PhysicalMapper { - unsafe fn map_aligned(&mut self, address: PhysicalAddress, _size: usize) -> Result { - Ok(VirtualAddress(address.0)) - } - - unsafe fn unmap_aligned(&mut self, _address: VirtualAddress) -> Result<(), &'static str> { - Ok(()) - } - - fn page_size(&self) -> usize { - 4096 - } -} - -pub static COREBOOT_SERIAL: Mutex> = Mutex::new(None); - -pub fn init() { - let _ = coreboot_table::tables(|table| { - #[allow(clippy::single_match)] - match table { - Table::Serial(serial) => { - *COREBOOT_SERIAL.lock() = Some(*serial); - }, - _ => (), - } - Ok(()) - }, &mut PhysicalMapper); -} diff --git a/src/main.rs b/src/main.rs index 7d8d291..ae0edf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,6 @@ use std::prelude::*; use core::ptr; -mod coreboot; mod display; mod hii; pub mod image; @@ -29,8 +28,6 @@ pub extern "C" fn main() -> Status { let _ = (uefi.BootServices.SetWatchdogTimer)(0, 0, 0, ptr::null()); - coreboot::init(); - if let Err(err) = fde::Fde::install() { println!("Fde error: {:?}", err); let _ = key::key(true); From 665e6494ed030bad46ef446fef77a99b2a520610 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Fri, 29 Nov 2024 22:02:39 -0700 Subject: [PATCH 3/3] Misc cleanups - Move default target and rustflags to `.cargo/config.toml` - Remove use of mtools/parted and use target directory as a drive - Remove `startup.nsh` script and document how to load the driver in QEMU - Remove `deps.sh` now that Make and Rust are the only dependencies - Replace use of `emit` with specifying the normal binary path Signed-off-by: Tim Crawford --- .cargo/config.toml | 15 ++++++++-- .github/workflows/ci.yml | 4 ++- Makefile | 65 +++++++++++----------------------------- README.md | 18 ++++++++++- deps.sh | 10 ------- firmware-setup.inf | 13 ++------ res/startup.nsh | 49 ------------------------------ 7 files changed, 53 insertions(+), 121 deletions(-) delete mode 100755 deps.sh delete mode 100644 res/startup.nsh diff --git a/.cargo/config.toml b/.cargo/config.toml index 70f9eae..8b6e8d5 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,13 @@ -[registries.crates-io] -protocol = "sparse" +[build] +target = "x86_64-unknown-uefi" + +[target.x86_64-unknown-uefi] +rustflags = [ + "-Clink-arg=/heap:0,0", + "-Clink-arg=/stack:0,0", + "-Clink-arg=/dll", + "-Clink-arg=/base:0", + "-Clink-arg=/align:32", + "-Clink-arg=/filealign:32", + "-Clink-arg=/subsystem:efi_boot_service_driver" +] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88c7555..bb750d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,9 @@ jobs: submodules: true - name: Install dependencies - run: ./deps.sh + run: | + sudo apt install --yes make + rustup show - name: Build UEFI application run: make diff --git a/Makefile b/Makefile index 8de0153..73d9c03 100644 --- a/Makefile +++ b/Makefile @@ -1,55 +1,26 @@ # SPDX-License-Identifier: GPL-3.0-only TARGET = x86_64-unknown-uefi -BUILD = build/$(TARGET) +QEMU = qemu-system-x86_64 +OVMF = /usr/share/OVMF -all: $(BUILD)/boot.efi +.PHONY: build +build: + cargo build --release +.PHONY: clean clean: cargo clean - rm -rf build -update: - git submodule update --init --recursive --remote - cargo update - -$(BUILD)/OVMF_VARS.fd: /usr/share/OVMF/OVMF_VARS.fd - cp $< $@ - -qemu: $(BUILD)/boot.img $(BUILD)/OVMF_VARS.fd - kvm -M q35 -m 1024 -net none -vga std $< \ - -drive if=pflash,format=raw,readonly,file=/usr/share/OVMF/OVMF_CODE.fd \ - -drive if=pflash,format=raw,file=$(BUILD)/OVMF_VARS.fd \ - -chardev stdio,id=debug -device isa-debugcon,iobase=0x402,chardev=debug - -$(BUILD)/boot.img: $(BUILD)/efi.img - dd if=/dev/zero of=$@.tmp bs=512 count=100352 - parted $@.tmp -s -a minimal mklabel gpt - parted $@.tmp -s -a minimal mkpart EFI FAT16 2048s 93716s - parted $@.tmp -s -a minimal toggle 1 boot - dd if=$< of=$@.tmp bs=512 count=98304 seek=2048 conv=notrunc - mv $@.tmp $@ - -$(BUILD)/efi.img: $(BUILD)/boot.efi - dd if=/dev/zero of=$@.tmp bs=512 count=98304 - mkfs.vfat $@.tmp - mmd -i $@.tmp efi - mmd -i $@.tmp efi/boot - mcopy -i $@.tmp $< ::driver.efi - mcopy -i $@.tmp res/startup.nsh ::startup.nsh - mv $@.tmp $@ - -$(BUILD)/boot.efi: Cargo.lock Cargo.toml res/* src/* src/*/* - mkdir -p $(BUILD) - cargo rustc \ - --target $(TARGET) \ - --release \ - -- \ - -C link-arg=/heap:0,0 \ - -C link-arg=/stack:0,0 \ - -C link-arg=/dll \ - -C link-arg=/base:0 \ - -C link-arg=/align:32 \ - -C link-arg=/filealign:32 \ - -C link-arg=/subsystem:efi_boot_service_driver \ - --emit link=$@ +.PHONY: qemu +qemu: build $(OVMF)/OVMF_VARS.fd $(OVMF)/OVMF_CODE.fd + cp $(OVMF)/OVMF_CODE.fd target/ + cp $(OVMF)/OVMF_VARS.fd target/ + $(QEMU) -enable-kvm -M q35 -m 1024 -vga std \ + -chardev stdio,mux=on,id=debug \ + -device isa-serial,index=2,chardev=debug \ + -device isa-debugcon,iobase=0x402,chardev=debug \ + -drive if=pflash,format=raw,readonly=on,file=target/OVMF_CODE.fd \ + -drive if=pflash,format=raw,readonly=on,file=target/OVMF_VARS.fd \ + -drive format=raw,file=fat:rw:target/$(TARGET) \ + -net none diff --git a/README.md b/README.md index b091136..2a91cb2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,21 @@ # System76 Firmware Setup -firmware-setup is a UEFI application that implements the user interface for +firmware-setup is a UEFI driver that implements the user interface for System76 Open Firmware. It is basic by design, with its only functionality being selecting the boot device and changing the boot order. + +## Testing + +As a basic test, the driver can be loaded in QEMU to use the UI. + +``` +make qemu +``` + +In QEMU: + +``` +Shell> fs0: +FS0:\> load release\system76_firmware_setup.efi +FS0:\> exit +``` diff --git a/deps.sh b/deps.sh deleted file mode 100755 index 0102cc6..0000000 --- a/deps.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -sudo apt-get install \ - --yes \ - make \ - mtools \ - parted - -# Ensure the correct toolchain and components are installed -rustup show diff --git a/firmware-setup.inf b/firmware-setup.inf index 4542e54..c8da3b6 100644 --- a/firmware-setup.inf +++ b/firmware-setup.inf @@ -1,18 +1,9 @@ [Defines] - INF_VERSION = 0x00010005 + INF_VERSION = 1.5 BASE_NAME = system76-firmware-setup FILE_GUID = 76ff62c9-7915-4e98-b964-154524023fa7 MODULE_TYPE = UEFI_DRIVER VERSION_STRING = 1.0 - # - # The following information is for reference only and not required by the build tools. - # - # VALID_ARCHITECTURES = IA32 X64 IPF EBC - # - - VALID_ARCHITECTURES = X64 - [Binaries.X64] - PE32|build/x86_64-unknown-uefi/boot.efi|* - + PE32|target/x86_64-unknown-uefi/release/system76_firmware_setup.efi|* diff --git a/res/startup.nsh b/res/startup.nsh deleted file mode 100644 index af45f70..0000000 --- a/res/startup.nsh +++ /dev/null @@ -1,49 +0,0 @@ -@echo -off - -if exist "fs0:driver.efi" then - fs0: -endif - -if exist "fs1:driver.efi" then - fs1: -endif - -if exist "fs2:driver.efi" then - fs2: -endif - -if exist "fs3:driver.efi" then - fs3: -endif - -if exist "fs4:driver.efi" then - fs4: -endif - -if exist "fs5:driver.efi" then - fs5: -endif - -if exist "fs6:driver.efi" then - fs6: -endif - -if exist "fs7:driver.efi" then - fs7: -endif - -if exist "fs8:driver.efi" then - fs8: -endif - -if exist "fs9:driver.efi" then - fs9: -endif - -if not exist "driver.efi" then - echo "Did not find driver.efi" - exit 1 -endif - -load driver.efi -exit