interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

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.
3set -eu
4B=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
5KV=7.0.0-1019-nvidia
6M=/lib/modules/$KV
7BB=${BUSYBOX:-/bin/busybox}
8file -L "$BB" | grep -q 'statically linked' || { echo "busybox $BB not static" >&2; exit 1; }
9R=$(mktemp -d "$B/root.XXXXXX")
10trap 'rm -rf "$R"' EXIT
11mkdir -p "$R/bin" "$R/proc" "$R/sys" "$R/dev" "$R/lib/modules" "$R/tmp"
12cp "$BB" "$R/bin/busybox"
13for 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
15order=""
16add() { case " $order " in *" $1 "*) ;; *) order="$order $1";; esac; }
17for 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"
23done
24: > "$R/lib/modules/order"
25for 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"
29done
30echo "modules: $(cat "$R/lib/modules/order" | tr '\n' ' ')"
31cat > "$R/init" <<'INIT'
32#!/bin/sh
33export PATH=/bin
34mount -t proc proc /proc
35mount -t sysfs sysfs /sys
36mount -t devtmpfs devtmpfs /dev
37echo "=== bench init: $(uname -r)"
38dmesg | grep -i smmu
39for m in $(cat /lib/modules/order); do
40 insmod /lib/modules/$m && echo "insmod $m ok" || echo "insmod $m FAILED"
41done
42edu=""; other=""
43for 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
49done
50[ -n "$edu" ] || { echo "NO EDU DEVICE"; poweroff -f; }
51echo "=== edu bdf: $edu"
52echo 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
54echo $edu > /sys/bus/pci/drivers_probe
55echo "edu driver: $(readlink /sys/bus/pci/devices/$edu/driver)"
56ls -l /dev/vfio
57echo "edu iommu_group: $(readlink /sys/bus/pci/devices/$edu/iommu_group)"
58echo "=== second device (left unbound from vfio) bdf: $other"
59echo "second iommu_group: $(readlink /sys/bus/pci/devices/$other/iommu_group)"
60echo "second driver: $(readlink /sys/bus/pci/devices/$other/driver || echo none)"
61echo "vfio-pci bound: $(ls /sys/bus/pci/drivers/vfio-pci | grep : | tr '\n' ' ')"
62echo "=== cmds"
63if [ -f /cmds ]; then
64 while IFS= read -r c || [ -n "$c" ]; do
65 [ -n "$c" ] || continue
66 echo "\$ $c"
67 sh -c "$c" </dev/null
68 echo "rc=$?"
69 done < /cmds
70fi
71echo "=== bench done, powering off"
72poweroff -f
73INIT
74chmod +x "$R/init"
75(cd "$R" && find . | cpio -o -H newc --quiet) | gzip -9 > "$B/initramfs.cpio.gz"
76echo "wrote $B/initramfs.cpio.gz"