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

Misc cleanups #48

Merged
merged 3 commits into from
Dec 3, 2024
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
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
57 changes: 3 additions & 54 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,4 +20,3 @@ features = ["redox_hwio"]

[features]
default = []
debug = []
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
```
1 change: 0 additions & 1 deletion binutils.sha384

This file was deleted.

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.

35 changes: 0 additions & 35 deletions src/coreboot.rs

This file was deleted.

3 changes: 0 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::prelude::*;

use core::ptr;

mod coreboot;
mod display;
mod hii;
pub mod image;
Expand All @@ -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);
Expand Down