2022-07-05 01:46:29 +01:00
|
|
|
# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-09-17 14:29:58 +01:00
|
|
|
targets = kaem-optional hex0 hex2
|
2022-07-08 18:49:15 +01:00
|
|
|
ESP_SIZE_MIB = 50
|
2022-07-05 01:46:29 +01:00
|
|
|
QEMU = qemu-system-x86_64
|
2022-07-11 21:29:10 +01:00
|
|
|
|
2022-07-11 21:49:05 +01:00
|
|
|
QEMU_KVM = -enable-kvm
|
|
|
|
|
2022-07-11 21:29:10 +01:00
|
|
|
ifneq ($(wildcard /usr/share/OVMF/OVMF_CODE.fd),)
|
2022-07-12 19:02:57 +01:00
|
|
|
OVMF_IMG = /usr/share/OVMF/OVMF_CODE.fd
|
2022-07-11 21:29:10 +01:00
|
|
|
else
|
|
|
|
OVMF_IMG = /usr/share/edk2-ovmf/OVMF_CODE.fd
|
|
|
|
endif
|
2022-07-05 01:46:29 +01:00
|
|
|
|
2022-07-08 18:49:15 +01:00
|
|
|
ESP_SIZE_SECTORS = $$(($(ESP_SIZE_MIB) * 2048))
|
|
|
|
DISK_SIZE_SECTORS = $$(($(ESP_SIZE_SECTORS) + 2048 + 33))
|
2022-07-05 01:46:29 +01:00
|
|
|
|
|
|
|
cc = clang
|
2023-12-06 19:50:58 +00:00
|
|
|
cflags = -ffreestanding -MMD -mno-red-zone -std=c11 -target x86_64-pc-windows-coff -fno-PIE -fno-stack-protector
|
2022-07-05 01:46:29 +01:00
|
|
|
ld = lld-link
|
|
|
|
lflags = -subsystem:efi_application -nodefaultlib -dll
|
|
|
|
build_dir = build
|
|
|
|
rootfs_dir = $(build_dir)/rootfs
|
|
|
|
|
|
|
|
targets2 = $(addsuffix .efi, $(addprefix $(build_dir)/, $(targets)))
|
|
|
|
|
|
|
|
$(build_dir)/%.efi : $(build_dir)/%.o
|
|
|
|
$(ld) $(lflags) -entry:efi_main $< -out:$@
|
|
|
|
|
|
|
|
$(build_dir)/%.o : %.c
|
|
|
|
mkdir -p $(build_dir)
|
|
|
|
$(cc) $(cflags) -c $< -o $@
|
|
|
|
|
|
|
|
.PHONY : clean rootfs qemu
|
|
|
|
|
2022-08-20 15:33:06 +01:00
|
|
|
all: $(targets2)
|
|
|
|
|
2022-07-05 01:46:29 +01:00
|
|
|
qemu: $(build_dir)/disk.img $(OVMF_IMG)
|
2022-07-11 21:49:05 +01:00
|
|
|
$(QEMU) -cpu qemu64 -net none \
|
|
|
|
$(QEMU_KVM) \
|
2022-07-05 01:46:29 +01:00
|
|
|
-drive if=pflash,format=raw,unit=0,file=$(OVMF_IMG),readonly=on \
|
|
|
|
-drive if=ide,format=raw,file=$<
|
|
|
|
|
|
|
|
$(build_dir)/disk.img: $(build_dir)/esp.img
|
|
|
|
dd if=/dev/zero of=$@ bs=512 count=$(DISK_SIZE_SECTORS)
|
|
|
|
parted $@ -s -a minimal mklabel gpt
|
|
|
|
parted $@ -s -a minimal mkpart EFI FAT32 2048s $(ESP_SIZE_SECTORS)s
|
|
|
|
parted $@ -s -a minimal toggle 1 boot
|
|
|
|
dd if=$< of=$@ bs=512 seek=2048 conv=notrunc
|
|
|
|
|
|
|
|
$(build_dir)/esp.img: rootfs
|
|
|
|
dd if=/dev/zero of=$@ bs=512 count=$(ESP_SIZE_SECTORS)
|
|
|
|
mformat -i $@ -h 32 -t 32 -n 64 -c 1
|
|
|
|
mcopy -s -i $@ $(rootfs_dir)/* ::
|
|
|
|
|
2022-07-24 13:18:14 +01:00
|
|
|
rootfs: $(targets2) $(sources)
|
2022-07-05 01:46:29 +01:00
|
|
|
cp -R rootfs $(build_dir)
|
|
|
|
mkdir -p $(rootfs_dir)/EFI/BOOT/
|
2022-07-08 18:49:15 +01:00
|
|
|
cp $^ $(rootfs_dir)/EFI/BOOT/
|
2022-09-17 14:29:58 +01:00
|
|
|
mv $(rootfs_dir)/EFI/BOOT/kaem-optional.efi $(rootfs_dir)/EFI/BOOT/BOOTX64.EFI
|
2022-07-24 13:18:14 +01:00
|
|
|
cp ../amd64/hex0.hex0 $(rootfs_dir)/hex0_amd64.hex0
|
2022-07-05 01:46:29 +01:00
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf $(build_dir)
|