UEFI EDK II, TPM minting, QEMU launcher and basic DHCP support
Test Plan:
You still need a recent version of QEMU and swtpm installed (these are not yet integrated)
Run `make launch` and have fun with a running Smalltown instance :)
X-Origin-Diff: phab/D159
GitOrigin-RevId: c7245bfbabebf92507445525bee009a71d19caea
diff --git a/scripts/build_artifacts.sh b/scripts/build_artifacts.sh
new file mode 100755
index 0000000..9ec4d5c
--- /dev/null
+++ b/scripts/build_artifacts.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+set -eo pipefail
+
+if [ ! -d "$root/linux" ] ; then
+ echo "Please first call scripts/fetch_third_party.sh"
+fi
+
+root=$(git rev-parse --show-toplevel)/third_party
+
+# nasm + Python 3.7 + iasl
+if [ ! -d "$root/edk2" ] ; then
+ git clone --recurse-submodules https://github.com/tianocore/edk2 $root/edk2
+fi
+cd $root/edk2
+git checkout --recurse-submodules edk2-stable201908
+. edksetup.sh
+make -C $root/edk2/BaseTools/Source/C
+build -DTPM2_ENABLE -DSECURE_BOOT_ENABLE -t GCC5 -a X64 -b RELEASE -p $PWD/OvmfPkg/OvmfPkgX64.dsc
+
+musl_prefix=$root/musl-prefix
+
+cd $root/linux
+make headers_install ARCH=x86_64 INSTALL_HDR_PATH=$musl_prefix
+
+mkdir -p $root/musl
+curl -L https://www.musl-libc.org/releases/musl-1.1.23.tar.gz | tar -xzf - -C $root/musl --strip-components 1
+cd $root/musl
+
+./configure --prefix=$musl_prefix --syslibdir=$musl_prefix/lib
+make -j8
+make install
+
+mkdir -p $root/util-linux
+curl -L https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/snapshot/util-linux-2.34.tar.gz | tar -xzf - -C $root/util-linux --strip-components 1
+cd $root/util-linux
+./autogen.sh
+./configure CC=$musl_prefix/bin/musl-gcc --without-systemd --without-udev --without-btrfs --disable-pylibmount --without-tinfo --prefix=$musl_prefix --disable-makeinstall-chown --disable-makeinstall-setuid --with-bashcompletiondir=$musl_prefix/usr/share/bash-completion
+make -j8
+make install
+
+mkdir -p $root/xfsprogs-dev
+curl -L https://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git/snapshot/xfsprogs-dev-5.2.1.tar.gz | tar -xzf - -C $root/xfsprogs-dev --strip-components 1
+cd $root/xfsprogs-dev
+patch -p1 < ../../patches/xfsprogs-dev/*.patch
+./configure CC=$musl_prefix/bin/musl-gcc "CFLAGS=-static -I$musl_prefix/include -L$musl_prefix/lib" "LDFLAGS=-L$musl_prefix/lib"
+make -j8 mkfs
+cp $root/xfsprogs-dev/mkfs/mkfs.xfs
\ No newline at end of file
diff --git a/scripts/fetch_third_party.sh b/scripts/fetch_third_party.sh
new file mode 100755
index 0000000..c9edaca
--- /dev/null
+++ b/scripts/fetch_third_party.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+mkdir -p third_party/linux
+curl -L https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.72.tar.xz | tar -xJf - -C third_party/linux --strip-components 1
+ln -fs ../../kernel/linux-smalltown.config third_party/linux/.config
\ No newline at end of file
diff --git a/scripts/launch.sh b/scripts/launch.sh
new file mode 100755
index 0000000..7170bca
--- /dev/null
+++ b/scripts/launch.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+swtpm socket --tpmstate dir=$PWD/vm/tpm --ctrl type=unixio,path=$PWD/vm/tpm/swtpm-sock --tpm2 &
+
+qemu-system-x86_64 -cpu host -smp sockets=1,cpus=1,cores=2,threads=2,maxcpus=4 -m 1024 -machine q35 -enable-kvm -nographic -nodefaults \
+ -drive if=pflash,format=raw,readonly,file=$PWD/third_party/edk2/Build/OvmfX64/RELEASE_GCC5/FV/OVMF_CODE.fd \
+ -drive if=pflash,format=raw,snapshot=on,file=$PWD/third_party/edk2/Build/OvmfX64/RELEASE_GCC5/FV/OVMF_VARS.fd \
+ -drive if=virtio,format=raw,cache=unsafe,file=$PWD/vm/smalltown.img \
+ -netdev user,id=net0,hostfwd=tcp::7833-:7833,hostfwd=tcp::7834-:7834 \
+ -device virtio-net-pci,netdev=net0 \
+ -chardev socket,id=chrtpm,path=$PWD/vm/tpm/swtpm-sock \
+ -tpmdev emulator,id=tpm0,chardev=chrtpm \
+ -device tpm-tis,tpmdev=tpm0 \
+ -debugcon file:vm/debug.log \
+ -global isa-debugcon.iobase=0x402 \
+ -device ipmi-bmc-sim,id=ipmi0 \
+ -device virtio-rng-pci \
+ -serial mon:stdio
\ No newline at end of file