Skip to content

Build as a 'bin' crate, linking with rust-lld #14

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

Merged
merged 2 commits into from
Oct 16, 2020
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
5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ name = "system76_firmware_setup"
version = "1.0.0"
edition = "2018"

[lib]
name = "system76_firmware_setup"
path = "src/lib.rs"
crate-type = ["staticlib"]

[profile.release]
lto = true

Expand Down
34 changes: 2 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGET?=x86_64-efi-pe
TARGET?=x86_64-unknown-uefi-drv

export LD=ld
export RUST_TARGET_PATH=$(CURDIR)/targets
Expand Down Expand Up @@ -40,40 +40,10 @@ $(BUILD)/efi.img: $(BUILD)/boot.efi
mcopy -i [email protected] res/startup.nsh ::startup.nsh
mv [email protected] $@

$(BUILD)/boot.efi: $(BUILD)/boot.o
$(LD) \
-m i386pep \
--oformat pei-x86-64 \
--dll \
--image-base 0 \
--section-alignment 32 \
--file-alignment 32 \
--major-os-version 0 \
--minor-os-version 0 \
--major-image-version 0 \
--minor-image-version 0 \
--major-subsystem-version 0 \
--minor-subsystem-version 0 \
--subsystem 11 \
--heap 0,0 \
--stack 0,0 \
--pic-executable \
--entry _start \
--no-insert-timestamp \
$< -o $@
#--subsystem 10

$(BUILD)/boot.o: $(BUILD)/boot.a
rm -rf $(BUILD)/boot
mkdir $(BUILD)/boot
cd $(BUILD)/boot && ar x ../boot.a
ld -r $(BUILD)/boot/*.o -o $@

$(BUILD)/boot.a: Cargo.lock Cargo.toml res/* src/* src/*/*
$(BUILD)/boot.efi: Cargo.lock Cargo.toml res/* src/* src/*/*
mkdir -p $(BUILD)
cargo rustc \
-Z build-std=core,alloc \
--lib \
--target $(TARGET) \
--release \
-- \
Expand Down
2 changes: 1 addition & 1 deletion firmware-setup.inf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
VALID_ARCHITECTURES = X64

[Binaries.X64]
PE32|build/x86_64-efi-pe/boot.efi|*
PE32|build/x86_64-unknown-uefi-drv/boot.efi|*

1 change: 1 addition & 0 deletions src/lib.rs → src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_std]
#![no_main]
#![feature(llvm_asm)]
#![feature(const_fn)]
#![feature(core_intrinsics)]
Expand Down
30 changes: 0 additions & 30 deletions targets/x86_64-efi-pe.json

This file was deleted.

40 changes: 40 additions & 0 deletions targets/x86_64-unknown-uefi-drv.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"abi-return-struct-as-int": true,
"allows-weak-linkage": false,
"arch": "x86_64",
"code-model": "large",
"cpu": "x86-64",
"data-layout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
"disable-redzone": true,
"emit-debug-gdb-scripts": false,
"env": "",
"exe-suffix": ".efi",
"executables": true,
"features": "-mmx,-sse,+soft-float",
"is-builtin": true,
"linker": "rust-lld",
"linker-flavor": "lld-link",
"lld-flavor": "link",
"llvm-target": "x86_64-unknown-windows",
"max-atomic-width": 64,
"os": "uefi",
"panic-strategy": "abort",
"pre-link-args": {
"lld-link": [
"/entry:_start",
"/heap:0,0",
"/stack:0,0",
"/dll",
"/base:0",
"/align:32",
"/filealign:32",
"/subsystem:efi_boot_service_driver"
]
},
"singlethread": true,
"stack-probes": true,
"target-c-int-width": "32",
"target-endian": "little",
"target-pointer-width": "64",
"vendor": "unknown"
}