summary refs log tree commit diff
path: root/live/Makefile
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-01-11 14:04:50 +0000
committerAlyssa Ross <hi@alyssa.is>2022-01-11 14:34:29 +0000
commitc7c0c208be7288fb5f313005d76c048d76f8ba5d (patch)
treebc84cd37e39e6240638a44995598c0dec0804d93 /live/Makefile
parent3c859660a68097e281bda0126d29c639c08855d7 (diff)
downloadspectrum-c7c0c208be7288fb5f313005d76c048d76f8ba5d.tar
spectrum-c7c0c208be7288fb5f313005d76c048d76f8ba5d.tar.gz
spectrum-c7c0c208be7288fb5f313005d76c048d76f8ba5d.tar.bz2
spectrum-c7c0c208be7288fb5f313005d76c048d76f8ba5d.tar.lz
spectrum-c7c0c208be7288fb5f313005d76c048d76f8ba5d.tar.xz
spectrum-c7c0c208be7288fb5f313005d76c048d76f8ba5d.tar.zst
spectrum-c7c0c208be7288fb5f313005d76c048d76f8ba5d.zip
live: pull out of initramfs
This isn't really part of the initramfs, and them being mixed together
meant testing the initramfs was slow, because it had to build a whole
live image.
Diffstat (limited to 'live/Makefile')
-rw-r--r--live/Makefile71
1 files changed, 71 insertions, 0 deletions
diff --git a/live/Makefile b/live/Makefile
new file mode 100644
index 0000000..8b06a17
--- /dev/null
+++ b/live/Makefile
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: EUPL-1.2
+# SPDX-FileCopyrightText: 2021-2022 Alyssa Ross <hi@alyssa.is>
+
+# qemu-kvm is non-standard, but is present in at least Fedora and
+# Nixpkgs.  If you don't have qemu-kvm, you'll need to set e.g.
+# QEMU_KVM = qemu-system-x86_64 -enable-kvm.
+QEMU_KVM = qemu-kvm
+
+MCOPY = mcopy
+MKFS_FAT = mkfs.fat
+MMD = mmd
+OBJCOPY = objcopy
+SCRIPTS = ../scripts
+TRUNCATE = truncate
+VERITYSETUP = veritysetup
+
+build/live.img: $(SCRIPTS)/format-uuid.sh $(SCRIPTS)/make-gpt.sh build/boot.fat build/rootfs.verity.superblock build/rootfs.verity.roothash $(ROOT_FS) $(EXT_FS)
+	$(SCRIPTS)/make-gpt.sh $@.tmp \
+	    build/boot.fat:c12a7328-f81f-11d2-ba4b-00a0c93ec93b \
+	    build/rootfs.verity.superblock:2c7357ed-ebd2-46d9-aec1-23d437ec2bf5:$$($(SCRIPTS)/format-uuid.sh "$$(dd if=build/rootfs.verity.roothash bs=32 skip=1 count=1 status=none)") \
+	    $(ROOT_FS):4f68bce3-e8cd-4db1-96e7-fbcaf984b709:$$($(SCRIPTS)/format-uuid.sh "$$(head -c 32 build/rootfs.verity.roothash)") \
+	    $(EXT_FS):9293e1ff-cee4-4658-88be-898ec863944f
+	mv $@.tmp $@
+
+build/cmdline: build/rootfs.verity.roothash
+	printf "ro console=ttyS0 roothash=" > $@
+	cat build/rootfs.verity.roothash >> $@
+
+build/bootx64.efi: etc/os-release build/cmdline $(INITRAMFS)
+	$(OBJCOPY) --add-section .osrel=etc/os-release --change-section-vma .osrel=0x20000 \
+	    --add-section .cmdline=build/cmdline --change-section-vma .cmdline=0x30000 \
+	    --add-section .linux=$(KERNEL) --change-section-vma .linux=0x40000 \
+	    --add-section .initrd=$(INITRAMFS) --change-section-vma .initrd=0x3000000 \
+	    $(EFI_STUB) $@
+
+build/boot.fat: build/bootx64.efi
+	$(TRUNCATE) -s 157286400 $@
+	$(MKFS_FAT) $@
+	$(MMD) -i $@ ::/EFI ::/EFI/BOOT
+	$(MCOPY) -i $@ build/bootx64.efi ::/EFI/BOOT
+
+# veritysetup format produces two files, but Make only (portably)
+# supports one output per rule, so we combine the two outputs then
+# define two more rules to separate them again.
+build/rootfs.verity: $(ROOT_FS)
+	mkdir -p build
+	$(VERITYSETUP) format $(ROOT_FS) build/rootfs.verity.superblock.tmp \
+	    | awk -F ':[[:blank:]]*' '$$1 == "Root hash" {print $$2; exit}' \
+	    > build/rootfs.verity.roothash.tmp
+	cat build/rootfs.verity.roothash.tmp build/rootfs.verity.superblock.tmp \
+	    > $@
+	rm build/rootfs.verity.roothash.tmp build/rootfs.verity.superblock.tmp
+build/rootfs.verity.roothash: build/rootfs.verity
+	head -n 1 build/rootfs.verity > $@
+build/rootfs.verity.superblock: build/rootfs.verity
+	tail -n +2 build/rootfs.verity > $@
+
+clean:
+	rm -rf build
+.PHONY: clean
+
+run: build/live.img
+	$(QEMU_KVM) -m 4G \
+	    -bios $(OVMF_FD) \
+	    -cpu host \
+	    -display gtk,gl=on \
+	    -device virtio-vga-gl \
+	    -device qemu-xhci \
+	    -device usb-storage,drive=drive1,removable=true \
+	    -drive file=build/live.img,id=drive1,format=raw,if=none,readonly=true
+.PHONY: run