Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-gpu-driver/blob/main/qemu/bench/mkinit.sh # omega-gpu-driver aien-dev/omega-gpu-driver Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-gpu-driver / qemu / bench / mkinit.sh` 76 lines ยท 2959 bytes Raw Blame History 1 #!/bin/sh 2 # Build initramfs.cpio.gz next to this script: static busybox + vfio-pci/iommufd modules + /init. 3 set -eu 4 B=$(CDPATH= cd -- "$(dirname "$0")" && pwd) 5 KV=7.0.0-1019-nvidia 6 M=/lib/modules/$KV 7 BB=${BUSYBOX:-/bin/busybox} 8 file -L "$BB" | grep -q 'statically linked' || { echo "busybox $BB not static" >&2; exit 1; } 9 R=$(mktemp -d "$B/root.XXXXXX") 10 trap 'rm -rf "$R"' EXIT 11 mkdir -p "$R/bin" "$R/proc" "$R/sys" "$R/dev" "$R/lib/modules" "$R/tmp" 12 cp "$BB" "$R/bin/busybox" 13 for a in $("$BB" --list); do [ "$a" = busybox ] || ln -s busybox "$R/bin/$a"; done 14 # resolve deps from modules.dep: deps listed before the module itself, de-duplicated 15 order="" 16 add() { case " $order " in *" $1 "*) ;; *) order="$order $1";; esac; } 17 for want in kernel/drivers/vfio/pci/vfio-pci.ko.zst; do 18 line=$(grep "^$want:" "$M/modules.dep") || { echo "missing $want" >&2; exit 1; } 19 deps=${line#*:} 20 rev=""; for d in $deps; do rev="$d $rev"; done # modules.dep lists deepest dep last 21 for d in $rev; do add "$d"; done 22 add "$want" 23 done 24 : > "$R/lib/modules/order" 25 for m in $order; do 26 n=$(basename "$m" .zst) 27 zstd -q -d -c "$M/$m" > "$R/lib/modules/$n" 28 echo "$n" >> "$R/lib/modules/order" 29 done 30 echo "modules: $(cat "$R/lib/modules/order" | tr '\n' ' ')" 31 cat > "$R/init" <<'INIT' 32 #!/bin/sh 33 export PATH=/bin 34 mount -t proc proc /proc 35 mount -t sysfs sysfs /sys 36 mount -t devtmpfs devtmpfs /dev 37 echo "=== bench init: $(uname -r)" 38 dmesg | grep -i smmu 39 for m in $(cat /lib/modules/order); do 40 insmod /lib/modules/$m && echo "insmod $m ok" || echo "insmod $m FAILED" 41 done 42 edu=""; other="" 43 for d in /sys/bus/pci/devices/*; do 44 v=$(cat $d/vendor); i=$(cat $d/device); b=${d##*/} 45 echo "pci $b vendor=$v device=$i class=$(cat $d/class)" 46 if [ "$v" = 0x1234 ] && [ "$i" = 0x11e8 ]; then 47 if [ -z "$edu" ]; then edu=$b; elif [ -z "$other" ]; then other=$b; fi 48 fi 49 done 50 [ -n "$edu" ] || { echo "NO EDU DEVICE"; poweroff -f; } 51 echo "=== edu bdf: $edu" 52 echo vfio-pci > /sys/bus/pci/devices/$edu/driver_override 53 [ -e /sys/bus/pci/devices/$edu/driver ] && echo $edu > /sys/bus/pci/devices/$edu/driver/unbind 54 echo $edu > /sys/bus/pci/drivers_probe 55 echo "edu driver: $(readlink /sys/bus/pci/devices/$edu/driver)" 56 ls -l /dev/vfio 57 echo "edu iommu_group: $(readlink /sys/bus/pci/devices/$edu/iommu_group)" 58 echo "=== second device (left unbound from vfio) bdf: $other" 59 echo "second iommu_group: $(readlink /sys/bus/pci/devices/$other/iommu_group)" 60 echo "second driver: $(readlink /sys/bus/pci/devices/$other/driver || echo none)" 61 echo "vfio-pci bound: $(ls /sys/bus/pci/drivers/vfio-pci | grep : | tr '\n' ' ')" 62 echo "=== cmds" 63 if [ -f /cmds ]; then 64 while IFS= read -r c || [ -n "$c" ]; do 65 [ -n "$c" ] || continue 66 echo "\$ $c" 67 sh -c "$c" "$B/initramfs.cpio.gz" 76 echo "wrote $B/initramfs.cpio.gz"