Skip to content

Commit

Permalink
Enhance QEMU scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tmael committed Oct 10, 2023
1 parent e742385 commit e75cebc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
54 changes: 50 additions & 4 deletions tools/scripts/qemu64/qemu64-tpm.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
#!/bin/bash
#


# Usage:

# For DEBUG_STAGE1 without waiting for GDB: ./qemu64-tpm.sh -d DEBUG_STAGE1 -w
# For DEBUG_STAGE2 without waiting for GDB: ./qemu64-tpm.sh -w
# For DEBUG_STAGE1 with waiting for GDB (default): ./qemu64-tpm.sh -d DEBUG_STAGE1
# For DEBUG_STAGE2 with waiting for GDB (default): ./qemu64-tpm.sh


# To DEBUG_STAGE1
# $ gdb stage1/loader_stage1.elf
# target remote :1234
# b start
# c

# To DEBUG_STAGE2
# $ gdb wolfboot.elf
# target remote :1234
# b main
# c


## TPM emulator:
# https://github.com/stefanberger/swtpm

# Default values
DEBUG_STAGE="DEBUG_STAGE2"
WAIT_FOR_GDB=true

# Parse command line options
while getopts "d:w" opt; do
case "$opt" in
d)
DEBUG_STAGE="$OPTARG"
;;
w)
WAIT_FOR_GDB=false
;;
*)
echo "Usage: $0 [-d DEBUG_STAGE1 | DEBUG_STAGE2] [-w]"
exit 1
;;
esac
done

if (test -z $OVMF_PATH); then
if (test -f /usr/share/edk2-ovmf/x64/OVMF.fd); then
OVMF_PATH=/usr/share/edk2-ovmf/x64
Expand All @@ -24,10 +65,15 @@ QEMU_OPTIONS=" \
-pflash wolfboot_stage1.bin -drive id=mydisk,format=raw,file=app.bin,if=none \
-device ide-hd,drive=mydisk"

QEMU=qemu-system-x86_64
if [ "$DEBUG" = "1" ]; then
# If waiting for GDB is true, append options to QEMU_OPTIONS
if [ "$WAIT_FOR_GDB" = true ]; then
QEMU_OPTIONS="${QEMU_OPTIONS} -S -s"
fi

if [ "$DEBUG_STAGE" = "DEBUG_STAGE1" ]; then
QEMU=qemu-system-i386
else
QEMU=qemu-system-x86_64
fi

killall swtpm
Expand All @@ -39,5 +85,5 @@ swtpm socket --tpm2 --tpmstate dir=/tmp/swtpm \
sleep .5
echo Running QEMU...

echo "$QEMU $QEMU_OPTIONS $QEMU_TPM_OPTIONS"
$QEMU $QEMU_OPTIONS $QEMU_TPM_OPTIONS

16 changes: 12 additions & 4 deletions tools/x86_fsp/qemu/qemu_build_fsp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ else
fi

download_edkii() {
(cd "$WORK_DIR" &&
git clone "${EDKII_REPO}" edk2 &&
cd edk2 &&
git checkout "${EDKII_TAG}")
if [ ! -d "$WORK_DIR/edk2" ]; then
(cd "$WORK_DIR" &&
git clone "${EDKII_REPO}" edk2)
else
(cd "$WORK_DIR/edk2" &&
git stash save --include-untracked "Auto-stashed on $(date)" &&
git clean -fd) # This will remove untracked files/directories
fi

# Now, checkout the desired tag/branch
(cd "$WORK_DIR/edk2" &&
git checkout "${EDKII_TAG}")
}

download_sbl_patch_and_patch_edkii() {
Expand Down

0 comments on commit e75cebc

Please sign in to comment.