aboutsummaryrefslogtreecommitdiffstats
path: root/openbsd-image/Makefile
blob: 0c3ae00a10f2eac03e64420be261d2c35a793c89 (plain) (blame)
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
65
66
67
68
69
70
71
72
73
# TODO: Replace with run-openbsd-image.sh and add ARM support to build-openbsd-image.sh
SHELL := /bin/sh

ARCH        ?= arm64
BUILD_DIR   := build
EDK2_DIR    := /opt/homebrew/share/qemu
SSH_PORT    := 2222
SSH_USER    := admin
SSH_KEY     := ~/.ssh/id_rsa
CPU         := 8
MEMORY      := 32768M
PACKER_LOG  := 1

VERSION       := 7.9
VERSION_SHORT := 79
QEMU_ARCH     := $(if $(filter arm64,$(ARCH)),aarch64,x86_64)
VARS_FILE     := openbsd$(VERSION_SHORT)-$(ARCH).pkvars.hcl
DISK          := $(BUILD_DIR)/openbsd-$(VERSION)-$(QEMU_ARCH).qcow2
EFIVARS_RUN   := $(BUILD_DIR)/efivars-run.fd
EDK2_CODE     := $(EDK2_DIR)/edk2-aarch64-code.fd
EDK2_VARS     := edk2-arm-vars.fd

export PACKER_LOG

.PHONY: all init build run ssh clean

all: build

init:
	packer init .

build: init clean
ifeq ($(ARCH),arm64)
	cp $(EDK2_DIR)/$(EDK2_VARS) ./$(EDK2_VARS)
endif
	packer build -only qemu.openbsd-$(ARCH) -var-file=$(VARS_FILE) .

# Run the headless VM (SSH via port-forwarded localhost:$(SSH_PORT))
run:
ifeq ($(ARCH),arm64)
	cp ./$(EDK2_VARS) $(EFIVARS_RUN)
	qemu-system-aarch64 \
	  -machine type=virt,accel=hvf \
	  -cpu host \
	  -m $(MEMORY) \
	  -smp $(CPU) \
	  -nographic \
	  -device qemu-xhci,id=xhci \
	  -device usb-kbd,bus=xhci.0 \
	  -device virtio-gpu-pci \
	  -netdev user,id=net0,hostfwd=tcp::$(SSH_PORT)-:22 \
	  -device virtio-net,netdev=net0 \
	  -drive file=$(DISK),if=virtio,cache=writeback,discard=ignore,format=qcow2 \
	  -drive file=$(EDK2_CODE),if=pflash,unit=0,format=raw,readonly=on \
	  -drive file=$(EFIVARS_RUN),if=pflash,unit=1,format=raw
else
	qemu-system-x86_64 \
	  -machine type=q35,accel=tcg \
	  -cpu max \
	  -m $(MEMORY) \
	  -smp $(CPU) \
	  -nographic \
	  -netdev user,id=net0,hostfwd=tcp::$(SSH_PORT)-:22 \
	  -device virtio-net,netdev=net0 \
	  -drive file=$(DISK),if=virtio,cache=writeback,discard=ignore,format=qcow2
endif

ssh:
	ssh -i $(SSH_KEY) -p $(SSH_PORT) $(SSH_USER)@127.0.0.1

clean:
	rm -rf $(BUILD_DIR)