From 2b52c744fe6b2a47dfae8b27587d5ea51d04e2d6 Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Sun, 27 Feb 2022 21:29:29 +0100 Subject: [PATCH] Add more comments and convert some variables to local variables --- lib/get_GPU_GROUP.sh | 2 +- lib/get_GPU_ROM.sh | 4 ++-- lib/get_USB_CTL_GROUP.sh | 3 ++- lib/set_CMDLINE.sh | 2 +- vfio-setup | 2 ++ 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/get_GPU_GROUP.sh b/lib/get_GPU_GROUP.sh index e738b58..5f453ee 100755 --- a/lib/get_GPU_GROUP.sh +++ b/lib/get_GPU_GROUP.sh @@ -33,7 +33,7 @@ then # Get the PCI ids local PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | cut -d " " -f 4 | perl -pe "s/\n/ /" | perl -pe "s/\s$//") - # Write the currently unused vfio config for quickemu + # Write the GPU_PCI_IDs to the config that quickemu might make use of in the future printf "GPU_PCI_ID=($PCI_ID) USB_CTL_ID=\"\" " > "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf" diff --git a/lib/get_GPU_ROM.sh b/lib/get_GPU_ROM.sh index 21830dc..7a13198 100755 --- a/lib/get_GPU_ROM.sh +++ b/lib/get_GPU_ROM.sh @@ -23,9 +23,9 @@ echo 0 | sudo tee $VBIOS_PATH echo 1 | sudo tee $VBIOS_PATH sudo cat $VBIOS_PATH > "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" sudo md5sum $VBIOS_PATH | cut -d " " -f 1 > "$SCRIPTDIR/$QUICKEMU/vfio_card.rom.md5" - ROM_MD5=$(sudo md5sum $VBIOS_PATH | cut -d " " -f 1) + local ROM_MD5=$(sudo md5sum $VBIOS_PATH | cut -d " " -f 1) echo 0 | sudo tee $VBIOS_PATH - ROMFILE_MD5=$(md5sum "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" | cut -d " " -f 1) + local ROMFILE_MD5=$(md5sum "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" | cut -d " " -f 1) if [ -f $SCRIPTDIR/$QUICKEMU/vfio_card.rom ]; then diff --git a/lib/get_USB_CTL_GROUP.sh b/lib/get_USB_CTL_GROUP.sh index ca9bedf..3d0f512 100755 --- a/lib/get_USB_CTL_GROUP.sh +++ b/lib/get_USB_CTL_GROUP.sh @@ -24,8 +24,9 @@ read -p "Enter the id for the device you want to passthrough: " USB_CTL_DEVID if [[ $USB_CTL_DEVID =~ : ]]; then # Get the PCI ids - PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | cut -d " " -f 4) + local PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | cut -d " " -f 4) + # Replace the blank USB_CTL_ID with the PCI_ID for the usb controller the user wants to pass through perl -pi -e "s/USB_CTL_ID=\"\"/USB_CTL_ID=\"$PCI_ID\"/" "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf" exec "$SCRIPTDIR/lib/set_CMDLINE.sh" else diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh index 3522294..acea2e5 100755 --- a/lib/set_CMDLINE.sh +++ b/lib/set_CMDLINE.sh @@ -5,7 +5,7 @@ function set_CMDLINE () { # Get the config paths source "$SCRIPTDIR/lib/paths.sh" - CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args") + local CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args") printf "Configuration is now complete, however no changes have been done to your system. The files needed have just been written to $SCRIPTDIR/config/etc diff --git a/vfio-setup b/vfio-setup index 50889f7..36decf5 100755 --- a/vfio-setup +++ b/vfio-setup @@ -63,9 +63,11 @@ then rm -r "$SCRIPTDIR/config" fi +# Get the CPU Vendor CPU_VENDOR=$(cat /proc/cpuinfo | grep vendor | head -1 | cut -f 2 | cut -d " " -f 2) CMDLINE="iommu=pt" +# Adjust our kernel_args based on cpu vendor if [ "$CPU_VENDOR" == "GenuineIntel" ]; then CMDLINE="$CMDLINE intel_iommu=on"