From 5aea5d66d40b33c6acfb435e89e9727d30568ce3 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Fri, 29 Nov 2024 22:02:39 -0700 Subject: [PATCH] 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