Skip to content

Commit

Permalink
Misc cleanups
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
crawfxrd authored and jackpot51 committed Dec 3, 2024
1 parent 9c6ff86 commit 5aea5d6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 121 deletions.
15 changes: 13 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"
]
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
65 changes: 18 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
```
10 changes: 0 additions & 10 deletions deps.sh

This file was deleted.

13 changes: 2 additions & 11 deletions firmware-setup.inf
Original file line number Diff line number Diff line change
@@ -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|*
49 changes: 0 additions & 49 deletions res/startup.nsh

This file was deleted.

0 comments on commit 5aea5d6

Please sign in to comment.