summaryrefslogtreecommitdiff
path: root/partitions/Makefile
blob: 1007a5c573a8b5ea4f04d1dae3b22a3b9ad0a10c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

.PHONY: all clean

all: whole.img

stage0_efi_file = ../import-grub-bootx64-efi/3/BOOTX64.EFI
$(stage0_efi_file):
	make -C ../import-grub-bootx64-efi ver=3

whole.img: $(stage0_efi_file)
	partvi

key.img: $(stage0_efi_file)
	partvi key

PERSIST_SIZE=20G
persist.img:
	[ ! -e $@ ]
	fallocate -l "$(PERSIST_SIZE)" $@
	truncate -s 0 $@
	truncate -s "$(PERSIST_SIZE)" $@

persist := $(shell [ -e persist.img ] && printf %s '-drive file=persist.img,media=disk,driver=raw' || true)

.PHONY: usb emu key emu-key keymu
usb: whole.img
	usb=$$(usb) && sudo dd status=progress if="$<" of="$$usb"

# QEMU_DISPLAY_OPTIONS = -nographic
QEMU_DISPLAY_OPTIONS = -display gtk

QEMU_OPTIONS = $(QEMU_BIOS_OPTIONS) $(QEMU_DISPLAY_OPTIONS)

define emu
	NO_AT_BRIDGE=1 qemu-system-x86_64 ${QEMU_OPTIONS} -m 800 -enable-kvm -boot c \
	  -drive file=$(1),media=disk,driver=raw \
	  $(persist)
endef

emu: whole.img
	$(call emu,$<)

emu-key keymu: key.img
	$(call emu,$<)

key: key.img
	usb=$$(usb) && \
		sudo dd status=progress bs=1048576 if="$<" of="$$usb" && \
		sudo $(call emu,"$$usb")

efi: QEMU_BIOS_OPTIONS = -bios /usr/share/ovmf/OVMF.fd
efi: emu

efi-ventoy: QEMU_BIOS_OPTIONS = -bios /usr/share/ovmf/OVMF.fd
efi-ventoy: ventoy-efi-example.img
	$(call emu,$<)

clean:
	rm -rf _build whole.img key.img

.PHONY: total-destroy
total-destroy: clean
	rm -f persist.img
	$(MAKE) persist.img