revised to build raw EFI disk
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Wed, 5 May 2021 03:50:24 +0000 (13:50 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Wed, 5 May 2021 03:50:24 +0000 (13:50 +1000)
Makefile

index 3f6972b095a456029aa65f9063d12f5e007fced9..3d9b5b5f5cecf238d98a7c2bbcc6399003661654 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,27 +1,44 @@
+default: out/main
+
+# asm and init order is important
+src/main.asm: src/uefi.asm src/impl.asm src/bootstrap.asm
+src/main.asm: init/sys.f init/uefi.f
+
+out:
+       mkdir -p out
+
+out/main: src/main.asm | out
+       fasm $< $@
+
+# Start script
+out/startup.nsh: out
+       echo 'fs0:main' > $@
+
 .PHONY: qemu
+
+# Based on https://wiki.osdev.org/UEFI#Emulation_with_QEMU_and_OVMF
+qemu: ARGS = -cpu qemu64
+qemu: ARGS += -drive if=pflash,format=raw,unit=0,file=OVMF_CODE.fd,readonly=on
+qemu: ARGS += -drive if=pflash,format=raw,unit=1,file=OVMF_VARS.fd
+qemu: ARGS += -net none
+qemu: ARGS += -drive format=raw,file=fat:rw:out
+qemu: ARGS += -display type=gtk,zoom-to-fit=on
 qemu: out/main out/startup.nsh OVMF_CODE.fd OVMF_VARS.fd
-       # Based on https://wiki.osdev.org/UEFI#Emulation_with_QEMU_and_OVMF
-       qemu-system-x86_64 -cpu qemu64 \
-               -drive if=pflash,format=raw,unit=0,file=OVMF_CODE.fd,readonly=on \
-               -drive if=pflash,format=raw,unit=1,file=OVMF_VARS.fd \
-               -net none \
-               -drive format=raw,file=fat:rw:out \
-               -display type=gtk,zoom-to-fit=on
-
-# Assuming 'ovmf' package on Arch Linux is installed.
-OVMF_CODE.fd: /usr/share/ovmf/x64/OVMF_CODE.fd
-       cp $< $@
-OVMF_VARS.fd: /usr/share/ovmf/x64/OVMF_VARS.fd
+       qemu-system-x86_64 $(ARGS)
+
+OVMF_CODE.fd OVMF_VARS.fd: %: /usr/share/OVMF/%
        cp $< $@
 
-out/main: src/main.asm src/impl.asm src/bootstrap.asm src/uefi.asm init/sys.f init/uefi.f
-       mkdir -p out
-       fasm $< $@
+OVMF: OVMF_CODE.fd OVMF_VARS.fd
 
-out/startup.nsh:
-       mkdir -p out
-       echo 'fs0:main' >out/startup.nsh
+EFI.raw: out/main
+       mkfs.fat -C $@ 2048 # =1Mb
+       mmd -i "$@" ::efi
+       mmd -i "$@" ::efi/boot
+       mcopy -i "$@" out/main "::EFI/BOOT/bootx64.efi"
 
 .PHONY: clean
 clean:
-       rm -rf out OVMF_CODE.fd OVMF_VARS.fd
+       rm -rf out OVMF_CODE.fd OVMF_VARS.fd EFI.raw
+
+