From e4892beeaf292be641287bdb08cf38901f736c76 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Tue, 6 Aug 2024 13:19:52 +0000 Subject: [PATCH 1/2] freebsd: Document how to build on FreeBSD Signed-off-by: Daniel Schaefer --- README.md | 13 +++++++++++++ framework_uefi/Makefile | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 80ad816..dc4823b 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,8 @@ cargo build -p framework_tool ls -l target/debug/framework_tool # Build the UEFI application +# Needs mtools installed via your OS package manager +# See in FreeBSD section for building on FreeBSD # Can't be built with cargo! That's why we need to exclude it in the other commands. make -C framework_uefi ls -l framework_uefi/build/x86_64-unknown-uefi/boot.efi @@ -311,3 +313,14 @@ cargo build --no-default-features --features freebsd # Running the tool cargo run --no-default-features --features freebsd ``` + +Build UEFI tool + +``` +# Build just tool +gmake -C framework_uefi build/x86_64-unknown-uefi/boot.efi + +# Build QEMU image +# TODO: Does not work yet, need a replacement for GNU parted +gmake -C framework_uefi MKFS=newfs_msdos +``` diff --git a/framework_uefi/Makefile b/framework_uefi/Makefile index eb40a02..9f8bb3c 100644 --- a/framework_uefi/Makefile +++ b/framework_uefi/Makefile @@ -3,6 +3,8 @@ BUILD=build/$(TARGET) SRC_DIR=. +MKFS=mkfs.vfat + QEMU?=qemu-system-x86_64 QEMU_FLAGS=\ -M q35 \ @@ -33,7 +35,7 @@ $(BUILD)/boot.img: $(BUILD)/efi.img # Create filesystem with updater (bootx64.efi) $(BUILD)/efi.img: $(BUILD)/boot.efi dd if=/dev/zero of=$@.tmp bs=512 count=98304 - mkfs.vfat $@.tmp + $(MKFS) $@.tmp mmd -i $@.tmp efi mmd -i $@.tmp efi/boot mcopy -i $@.tmp $< ::efi/boot/bootx64.efi From 6fba9fa660b0caa0bef8d54dfa0019ff39ec8fa3 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 9 Aug 2024 14:07:58 +0800 Subject: [PATCH 2/2] freebsd: Build UEFI QEMU image Signed-off-by: Daniel Schaefer --- framework_uefi/Makefile | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/framework_uefi/Makefile b/framework_uefi/Makefile index 9f8bb3c..44b22ae 100644 --- a/framework_uefi/Makefile +++ b/framework_uefi/Makefile @@ -3,44 +3,36 @@ BUILD=build/$(TARGET) SRC_DIR=. -MKFS=mkfs.vfat - +# sudo pkg install qemu edk2-qemu-x64 QEMU?=qemu-system-x86_64 +OVMF_FD?=/usr/local/share/edk2-qemu/QEMU_UEFI-x86_64.fd QEMU_FLAGS=\ -M q35 \ -m 1024 \ -net none \ -vga std \ - -bios /usr/share/OVMF/OVMF_CODE.fd + -bios /usr/local/share/edk2-qemu/QEMU_UEFI-x86_64.fd .PHONY: qemu clean all: $(BUILD)/boot.img +$(BUILD)/boot.img: $(BUILD)/boot.efi + mkdir -p temp/EFI/BOOT + cp $(BUILD)/boot.efi temp/EFI/BOOT/bootx64.efi + makefs -t msdos \ + -o fat_type=16 \ + -o sectors_per_cluster=1 \ + -s 10000k \ + $(BUILD)/boot.img temp + rm -rf temp + clean: rm -r $(BUILD) qemu: $(BUILD)/boot.img $(QEMU) $(QEMU_FLAGS) $< -# Create ESP partition and filesystem -$(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 $@ - -# Create filesystem with updater (bootx64.efi) -$(BUILD)/efi.img: $(BUILD)/boot.efi - dd if=/dev/zero of=$@.tmp bs=512 count=98304 - $(MKFS) $@.tmp - mmd -i $@.tmp efi - mmd -i $@.tmp efi/boot - mcopy -i $@.tmp $< ::efi/boot/bootx64.efi - mv $@.tmp $@ - $(BUILD)/boot.efi: ../Cargo.lock $(SRC_DIR)/Cargo.toml $(SRC_DIR)/src/* mkdir -p $(BUILD) cargo rustc \