Skip to content

Commit c8e1141

Browse files
qemu: Deduplicate Qemu targets/documentation, extract from boards
The 8 qemu-* targets all contained nearly-identical copies of the targets to prepare the TPM/disk/etc. and then run Qemu. The only significant differences were for TPM1/TPM2 (extra swtpm_setup step, addition of --tpm2 to swtpm_setup and swtpm). ROOT_DISK_IMG used := or = differently in some boards, := was kept. targets/qemu.mk now defines all Qemu targets and is included only for qemu-* boards (by defining BOARD_TARGETS in each of those boards). The documentation was moved from qemu-coreboot-fbwhiptail-tpm1-hotp/ qemu-coreboot-fbwhiptail-tpm1-htop.md to targets/qemu.md. The other 7 qemu boards' symlinks to that file were removed. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
1 parent 4a57c61 commit c8e1141

19 files changed

+122
-736
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ else
7474
$(error "Unexpected value of $$(CONFIG_TARGET_ARCH): $(CONFIG_TARGET_ARCH)")
7575
endif
7676

77+
ifneq "$(BOARD_TARGETS)" ""
78+
include targets/$(BOARD_TARGETS).mk
79+
endif
80+
7781
# Create directories if they don't already exist
7882
BUILD_LOG := $(shell mkdir -p "$(log_dir)")
7983
PACKAGES := $(shell mkdir -p "$(packages)")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ QEMU:
8181

8282
OS booting can be tested in QEMU using a software TPM. HOTP can be tested by forwarding a USB token from the host to the guest.
8383

84-
For more information and setup instructions, refer to the [qemu-coreboot-fbwhiptail-tpm1-hotp documentation](boards/qemu-coreboot-fbwhiptail-tpm1-hotp/qemu-coreboot-fbwhiptail-tpm1-hotp.md).
84+
For more information and setup instructions, refer to the [qemu documentation](targets/qemu.md).
8585

8686
coreboot console messages
8787
---

boards/qemu-coreboot-fbwhiptail-tpm1-hotp/qemu-coreboot-fbwhiptail-tpm1-hotp.config

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -70,93 +70,4 @@ export CONFIG_TPM=y
7070
export CONFIG_BOOT_DEV="/dev/vda1"
7171
export CONFIG_BOARD_NAME="qemu-coreboot-fbwhiptail-tpm1-hotp"
7272

73-
# Use the GPG-injected ROM if a key was given, since we can't reflash a GPG
74-
# keyring in QEMU. Otherwise use the plain ROM, some things can still be tested
75-
# that way without a GPG key.
76-
ifneq "$(PUBKEY_ASC)" ""
77-
QEMU_BOOT_ROM := $(build)/$(BOARD)/$(CB_OUTPUT_FILE_GPG_INJ)
78-
else
79-
QEMU_BOOT_ROM := $(build)/$(BOARD)/$(CB_OUTPUT_FILE)
80-
endif
81-
82-
#borrowed from https://github.com/orangecms/webboot/blob/boot-via-qemu/run-webboot.sh
83-
TPMDIR=$(build)/$(BOARD)/vtpm
84-
$(TPMDIR)/.manufacture:
85-
mkdir -p "$(TPMDIR)"
86-
swtpm_setup --tpm-state "$(TPMDIR)" --create-platform-cert --lock-nvram
87-
touch "$(TPMDIR)/.manufacture"
88-
ROOT_DISK_IMG:=$(build)/$(BOARD)/root.qcow2
89-
# Default to 20G disk
90-
QEMU_DISK_SIZE?=20G
91-
$(ROOT_DISK_IMG):
92-
qemu-img create -f qcow2 "$(ROOT_DISK_IMG)" $(QEMU_DISK_SIZE)
93-
# Remember the amount of memory so it doesn't have to be specified every time.
94-
# Default to 4G, most bootable OSes are not usable with less.
95-
QEMU_MEMORY_SIZE?=4G
96-
MEMORY_SIZE_FILE=$(build)/$(BOARD)/memory
97-
$(MEMORY_SIZE_FILE):
98-
@echo "$(QEMU_MEMORY_SIZE)" >"$(MEMORY_SIZE_FILE)"
99-
USB_FD_IMG=$(build)/$(BOARD)/usb_fd.raw
100-
$(USB_FD_IMG):
101-
dd if=/dev/zero bs=1M of="$(USB_FD_IMG)" bs=1M count=256
102-
# Debian obnoxiously does not include /usr/sbin in PATH for non-root, even
103-
# though it is meaningful to use mkfs.vfat (etc.) as non-root
104-
MKFS_VFAT=mkfs.vfat; \
105-
[ -x /usr/sbin/mkfs.vfat ] && MKFS_VFAT=/usr/sbin/mkfs.vfat; \
106-
"$$MKFS_VFAT" "$(USB_FD_IMG)"
107-
# Pass INSTALL_IMG=<path_to_img.iso> to attach an installer as a USB flash drive instead
108-
# of the temporary flash drive for exporting GPG keys.
109-
ifneq "$(INSTALL_IMG)" ""
110-
QEMU_USB_FD_IMG := $(INSTALL_IMG)
111-
else
112-
QEMU_USB_FD_IMG := $(USB_FD_IMG)
113-
endif
114-
# To forward a USB token, set USB_TOKEN to one of the following:
115-
# - NitrokeyPro - forwards a Nitrokey Pro by VID:PID
116-
# - NitrokeyStorage - forwards a Nitrokey Storage by VID:PID
117-
# - Nitrokey3NFC - forwards a Nitrokey 3 by VID:PID
118-
# - LibremKey - forwards a Librem Key by VID:PID
119-
# - <other> - Provide the QEMU usb-host parameters, such as
120-
# 'hostbus=<#>,hostport=<#>' or 'vendorid=<#>,productid=<#>'
121-
ifeq "$(USB_TOKEN)" "NitrokeyPro"
122-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=8352,productid=16648
123-
else ifeq "$(USB_TOKEN)" "NitrokeyStorage"
124-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=8352,productid=16649
125-
else ifeq "$(USB_TOKEN)" "Nitrokey3NFC"
126-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=8352,productid=17074
127-
else ifeq "$(USB_TOKEN)" "LibremKey"
128-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=12653,productid=19531
129-
else ifneq "$(USB_TOKEN)" ""
130-
QEMU_USB_TOKEN_DEV := -device "usb-host,$(USB_TOKEN)"
131-
endif
132-
133-
run: $(TPMDIR)/.manufacture $(ROOT_DISK_IMG) $(MEMORY_SIZE_FILE) $(USB_FD_IMG)
134-
swtpm socket \
135-
--tpmstate dir="$(TPMDIR)" \
136-
--flags "startup-clear" \
137-
--terminate \
138-
--ctrl type=unixio,path="$(TPMDIR)/sock" &
139-
sleep 0.5
140-
141-
-qemu-system-x86_64 -drive file="$(ROOT_DISK_IMG)",if=virtio \
142-
--machine q35,accel=kvm:tcg \
143-
-rtc base=utc \
144-
-smp "$$(nproc)" \
145-
-vga std \
146-
-m "$$(cat "$(MEMORY_SIZE_FILE)")" \
147-
-serial stdio \
148-
--bios "$(QEMU_BOOT_ROM)" \
149-
-object rng-random,filename=/dev/urandom,id=rng0 \
150-
-device virtio-rng-pci,rng=rng0 \
151-
-netdev user,id=u1 -device e1000,netdev=u1 \
152-
-chardev socket,id=chrtpm,path="$(TPMDIR)/sock" \
153-
-tpmdev emulator,id=tpm0,chardev=chrtpm \
154-
-device tpm-tis,tpmdev=tpm0 \
155-
-device qemu-xhci,id=usb \
156-
-device usb-tablet \
157-
-drive file="$(QEMU_USB_FD_IMG)",if=none,id=usb-fd-drive,format=raw \
158-
-device usb-storage,bus=usb.0,drive=usb-fd-drive \
159-
$(QEMU_USB_TOKEN_DEV) \
160-
161-
stty sane
162-
@echo
73+
BOARD_TARGETS := qemu

boards/qemu-coreboot-fbwhiptail-tpm1/qemu-coreboot-fbwhiptail-tpm1.config

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -71,93 +71,4 @@ export CONFIG_TPM=y
7171
export CONFIG_BOOT_DEV="/dev/vda1"
7272
export CONFIG_BOARD_NAME="qemu-coreboot-fbwhiptail-tpm1"
7373

74-
# Use the GPG-injected ROM if a key was given, since we can't reflash a GPG
75-
# keyring in QEMU. Otherwise use the plain ROM, some things can still be tested
76-
# that way without a GPG key.
77-
ifneq "$(PUBKEY_ASC)" ""
78-
QEMU_BOOT_ROM := $(build)/$(BOARD)/$(CB_OUTPUT_FILE_GPG_INJ)
79-
else
80-
QEMU_BOOT_ROM := $(build)/$(BOARD)/$(CB_OUTPUT_FILE)
81-
endif
82-
83-
#borrowed from https://github.com/orangecms/webboot/blob/boot-via-qemu/run-webboot.sh
84-
TPMDIR=$(build)/$(BOARD)/vtpm
85-
$(TPMDIR)/.manufacture:
86-
mkdir -p "$(TPMDIR)"
87-
swtpm_setup --tpm-state "$(TPMDIR)" --create-platform-cert --lock-nvram
88-
touch "$(TPMDIR)/.manufacture"
89-
ROOT_DISK_IMG:=$(build)/$(BOARD)/root.qcow2
90-
# Default to 20G disk
91-
QEMU_DISK_SIZE?=20G
92-
$(ROOT_DISK_IMG):
93-
qemu-img create -f qcow2 "$(ROOT_DISK_IMG)" $(QEMU_DISK_SIZE)
94-
# Remember the amount of memory so it doesn't have to be specified every time.
95-
# Default to 4G, most bootable OSes are not usable with less.
96-
QEMU_MEMORY_SIZE?=4G
97-
MEMORY_SIZE_FILE=$(build)/$(BOARD)/memory
98-
$(MEMORY_SIZE_FILE):
99-
@echo "$(QEMU_MEMORY_SIZE)" >"$(MEMORY_SIZE_FILE)"
100-
USB_FD_IMG=$(build)/$(BOARD)/usb_fd.raw
101-
$(USB_FD_IMG):
102-
dd if=/dev/zero bs=1M of="$(USB_FD_IMG)" bs=1M count=256
103-
# Debian obnoxiously does not include /usr/sbin in PATH for non-root, even
104-
# though it is meaningful to use mkfs.vfat (etc.) as non-root
105-
MKFS_VFAT=mkfs.vfat; \
106-
[ -x /usr/sbin/mkfs.vfat ] && MKFS_VFAT=/usr/sbin/mkfs.vfat; \
107-
"$$MKFS_VFAT" "$(USB_FD_IMG)"
108-
# Pass INSTALL_IMG=<path_to_img.iso> to attach an installer as a USB flash drive instead
109-
# of the temporary flash drive for exporting GPG keys.
110-
ifneq "$(INSTALL_IMG)" ""
111-
QEMU_USB_FD_IMG := $(INSTALL_IMG)
112-
else
113-
QEMU_USB_FD_IMG := $(USB_FD_IMG)
114-
endif
115-
# To forward a USB token, set USB_TOKEN to one of the following:
116-
# - NitrokeyPro - forwards a Nitrokey Pro by VID:PID
117-
# - NitrokeyStorage - forwards a Nitrokey Storage by VID:PID
118-
# - Nitrokey3NFC - forwards a Nitrokey 3 by VID:PID
119-
# - LibremKey - forwards a Librem Key by VID:PID
120-
# - <other> - Provide the QEMU usb-host parameters, such as
121-
# 'hostbus=<#>,hostport=<#>' or 'vendorid=<#>,productid=<#>'
122-
ifeq "$(USB_TOKEN)" "NitrokeyPro"
123-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=8352,productid=16648
124-
else ifeq "$(USB_TOKEN)" "NitrokeyStorage"
125-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=8352,productid=16649
126-
else ifeq "$(USB_TOKEN)" "Nitrokey3NFC"
127-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=8352,productid=17074
128-
else ifeq "$(USB_TOKEN)" "LibremKey"
129-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=12653,productid=19531
130-
else ifneq "$(USB_TOKEN)" ""
131-
QEMU_USB_TOKEN_DEV := -device "usb-host,$(USB_TOKEN)"
132-
endif
133-
134-
run: $(TPMDIR)/.manufacture $(ROOT_DISK_IMG) $(MEMORY_SIZE_FILE) $(USB_FD_IMG)
135-
swtpm socket \
136-
--tpmstate dir="$(TPMDIR)" \
137-
--flags "startup-clear" \
138-
--terminate \
139-
--ctrl type=unixio,path="$(TPMDIR)/sock" &
140-
sleep 0.5
141-
142-
-qemu-system-x86_64 -drive file="$(ROOT_DISK_IMG)",if=virtio \
143-
--machine q35,accel=kvm:tcg \
144-
-rtc base=utc \
145-
-smp "$$(nproc)" \
146-
-vga std \
147-
-m "$$(cat "$(MEMORY_SIZE_FILE)")" \
148-
-serial stdio \
149-
--bios "$(QEMU_BOOT_ROM)" \
150-
-object rng-random,filename=/dev/urandom,id=rng0 \
151-
-device virtio-rng-pci,rng=rng0 \
152-
-netdev user,id=u1 -device e1000,netdev=u1 \
153-
-chardev socket,id=chrtpm,path="$(TPMDIR)/sock" \
154-
-tpmdev emulator,id=tpm0,chardev=chrtpm \
155-
-device tpm-tis,tpmdev=tpm0 \
156-
-device qemu-xhci,id=usb \
157-
-device usb-tablet \
158-
-drive file="$(QEMU_USB_FD_IMG)",if=none,id=usb-fd-drive,format=raw \
159-
-device usb-storage,bus=usb.0,drive=usb-fd-drive \
160-
$(QEMU_USB_TOKEN_DEV) \
161-
162-
stty sane
163-
@echo
74+
BOARD_TARGETS := qemu

boards/qemu-coreboot-fbwhiptail-tpm1/qemu-coreboot-fbwhiptail-tpm1.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

boards/qemu-coreboot-fbwhiptail-tpm2-hotp/qemu-coreboot-fbwhiptail-tpm2-hotp.config

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -75,95 +75,4 @@ CONFIG_OPENSSL=y
7575
export CONFIG_BOOT_DEV="/dev/vda1"
7676
export CONFIG_BOARD_NAME="qemu-coreboot-fbwhiptail-tpm2-hotp"
7777

78-
# Use the GPG-injected ROM if a key was given, since we can't reflash a GPG
79-
# keyring in QEMU. Otherwise use the plain ROM, some things can still be tested
80-
# that way without a GPG key.
81-
ifneq "$(PUBKEY_ASC)" ""
82-
QEMU_BOOT_ROM := $(build)/$(BOARD)/$(CB_OUTPUT_FILE_GPG_INJ)
83-
else
84-
QEMU_BOOT_ROM := $(build)/$(BOARD)/$(CB_OUTPUT_FILE)
85-
endif
86-
87-
#borrowed from https://github.com/orangecms/webboot/blob/boot-via-qemu/run-webboot.sh
88-
TPMDIR=$(build)/$(BOARD)/vtpm
89-
$(TPMDIR)/.manufacture:
90-
mkdir -p "$(TPMDIR)"
91-
swtpm_setup --create-config-files skip-if-exist
92-
swtpm_setup --tpm-state "$(TPMDIR)" --create-platform-cert --lock-nvram --tpm2
93-
touch "$(TPMDIR)/.manufacture"
94-
ROOT_DISK_IMG=$(build)/$(BOARD)/root.qcow2
95-
# Default to 20G disk
96-
QEMU_DISK_SIZE?=20G
97-
$(ROOT_DISK_IMG):
98-
qemu-img create -f qcow2 "$(ROOT_DISK_IMG)" $(QEMU_DISK_SIZE)
99-
# Remember the amount of memory so it doesn't have to be specified every time.
100-
# Default to 4G, most bootable OSes are not usable with less.
101-
QEMU_MEMORY_SIZE?=4G
102-
MEMORY_SIZE_FILE=$(build)/$(BOARD)/memory
103-
$(MEMORY_SIZE_FILE):
104-
@echo "$(QEMU_MEMORY_SIZE)" >"$(MEMORY_SIZE_FILE)"
105-
USB_FD_IMG=$(build)/$(BOARD)/usb_fd.raw
106-
$(USB_FD_IMG):
107-
dd if=/dev/zero bs=1M of="$(USB_FD_IMG)" bs=1M count=256
108-
# Debian obnoxiously does not include /usr/sbin in PATH for non-root, even
109-
# though it is meaningful to use mkfs.vfat (etc.) as non-root
110-
MKFS_VFAT=mkfs.vfat; \
111-
[ -x /usr/sbin/mkfs.vfat ] && MKFS_VFAT=/usr/sbin/mkfs.vfat; \
112-
"$$MKFS_VFAT" "$(USB_FD_IMG)"
113-
# Pass INSTALL_IMG=<path_to_img.iso> to attach an installer as a USB flash drive instead
114-
# of the temporary flash drive for exporting GPG keys.
115-
ifneq "$(INSTALL_IMG)" ""
116-
QEMU_USB_FD_IMG := $(INSTALL_IMG)
117-
else
118-
QEMU_USB_FD_IMG := $(USB_FD_IMG)
119-
endif
120-
# To forward a USB token, set USB_TOKEN to one of the following:
121-
# - NitrokeyPro - forwards a Nitrokey Pro by VID:PID
122-
# - NitrokeyStorage - forwards a Nitrokey Storage by VID:PID
123-
# - Nitrokey3NFC - forwards a Nitrokey 3 by VID:PID
124-
# - LibremKey - forwards a Librem Key by VID:PID
125-
# - <other> - Provide the QEMU usb-host parameters, such as
126-
# 'hostbus=<#>,hostport=<#>' or 'vendorid=<#>,productid=<#>'
127-
ifeq "$(USB_TOKEN)" "NitrokeyPro"
128-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=8352,productid=16648
129-
else ifeq "$(USB_TOKEN)" "NitrokeyStorage"
130-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=8352,productid=16649
131-
else ifeq "$(USB_TOKEN)" "Nitrokey3NFC"
132-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=8352,productid=17074
133-
else ifeq "$(USB_TOKEN)" "LibremKey"
134-
QEMU_USB_TOKEN_DEV := -device usb-host,vendorid=12653,productid=19531
135-
else ifneq "$(USB_TOKEN)" ""
136-
QEMU_USB_TOKEN_DEV := -device "usb-host,$(USB_TOKEN)"
137-
endif
138-
139-
run: $(TPMDIR)/.manufacture $(ROOT_DISK_IMG) $(MEMORY_SIZE_FILE) $(USB_FD_IMG)
140-
swtpm socket \
141-
--tpm2 \
142-
--tpmstate dir="$(TPMDIR)" \
143-
--flags "startup-clear" \
144-
--terminate \
145-
--ctrl type=unixio,path="$(TPMDIR)/sock" &
146-
sleep 0.5
147-
148-
-qemu-system-x86_64 -drive file="$(ROOT_DISK_IMG)",if=virtio \
149-
--machine q35,accel=kvm:tcg \
150-
-rtc base=utc \
151-
-smp "$$(nproc)" \
152-
-vga std \
153-
-m "$$(cat "$(MEMORY_SIZE_FILE)")" \
154-
-serial stdio \
155-
--bios "$(QEMU_BOOT_ROM)" \
156-
-object rng-random,filename=/dev/urandom,id=rng0 \
157-
-device virtio-rng-pci,rng=rng0 \
158-
-netdev user,id=u1 -device e1000,netdev=u1 \
159-
-chardev socket,id=chrtpm,path="$(TPMDIR)/sock" \
160-
-tpmdev emulator,id=tpm0,chardev=chrtpm \
161-
-device tpm-tis,tpmdev=tpm0 \
162-
-device qemu-xhci,id=usb \
163-
-device usb-tablet \
164-
-drive file="$(QEMU_USB_FD_IMG)",if=none,id=usb-fd-drive,format=raw \
165-
-device usb-storage,bus=usb.0,drive=usb-fd-drive \
166-
$(QEMU_USB_TOKEN_DEV) \
167-
168-
stty sane
169-
@echo
78+
BOARD_TARGETS := qemu

boards/qemu-coreboot-fbwhiptail-tpm2-hotp/qemu-coreboot-fbwhiptail-tpm2-hotp.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)