Загрузка данных


cat > dump_8111h.sh << 'EOF'
#!/usr/bin/env bash
set -uo pipefail
OUT="${1:-$PWD/donor-8111h}"
mkdir -p "$OUT"
exec > >(tee -a "$OUT/dump.log") 2>&1

echo "== env =="
uname -a
command -v lsb_release >/dev/null && lsb_release -a

BDF=$(lspci -Dn | awk '$3 ~ /^10ec:8168/ {print $1; exit}')
[ -n "$BDF" ] || { echo "NO 10ec:8168"; lspci -Dnn; exit 1; }
echo "BDF=$BDF"
printf '%s\n' "$BDF" > "$OUT/bdf.txt"
DEV="/sys/bus/pci/devices/$BDF"

echo "== cold cfg =="
dd if="$DEV/config" of="$OUT/cfg.bin" bs=1 count=4096 status=none
lspci -vvv -s "$BDF" > "$OUT/lspci-vvv.txt"
lspci -xxx -s "$BDF" > "$OUT/lspci-hex.txt"
lspci -Dnn > "$OUT/lspci-nn.txt"
lspci -tv > "$OUT/lspci-tree.txt"

: > "$OUT/sysfs.txt"
for f in vendor device subsystem_vendor subsystem_device revision class \
         current_link_speed current_link_width max_link_speed max_link_width \
         irq enable power_state; do
  printf '%s: ' "$f" >> "$OUT/sysfs.txt"
  cat "$DEV/$f" >> "$OUT/sysfs.txt" 2>/dev/null || echo "n/a" >> "$OUT/sysfs.txt"
done

dd if="$DEV/resource0" of="$OUT/bar0-cold.bin" bs=1 count=4096 status=none 2>/dev/null

echo "== rom =="
sh -c "echo 1 > $DEV/rom" 2>/dev/null
dd if="$DEV/rom" of="$OUT/rom.bin" bs=512 count=128 status=none 2>/dev/null
sh -c "echo 0 > $DEV/rom" 2>/dev/null

echo "== mmiotrace =="
mount -t debugfs none /sys/kernel/debug 2>/dev/null
IFACE=$(ls "$DEV/net" 2>/dev/null | head -1)
echo "IFACE=$IFACE"
[ -n "$IFACE" ] && ip link set dev "$IFACE" down 2>/dev/null
modprobe -r r8169 2>/dev/null

TRACE=/sys/kernel/debug/tracing
echo 0 > $TRACE/tracing_on
echo > $TRACE/trace
echo mmiotrace > $TRACE/current_tracer

modprobe r8169
sleep 2
[ -n "$IFACE" ] && ip link set dev "$IFACE" up
sleep 3

echo 0 > $TRACE/tracing_on
cat $TRACE/trace > "$OUT/mmio.txt"
echo nop > $TRACE/current_tracer

echo "== post =="
[ -n "$IFACE" ] && ethtool -i "$IFACE" > "$OUT/ethtool-i.txt" 2>&1
[ -n "$IFACE" ] && ethtool -k "$IFACE" > "$OUT/ethtool-k.txt" 2>&1
cat /proc/interrupts > "$OUT/interrupts.txt"
dd if="$DEV/resource0" of="$OUT/bar0-live.bin" bs=1 count=4096 status=none 2>/dev/null
dmesg > "$OUT/dmesg.txt"

echo "== pack =="
tar czf "$OUT.tar.gz" -C "$(dirname "$OUT")" "$(basename "$OUT")"
sha256sum "$OUT.tar.gz" > "$OUT.tar.gz.sha256"
echo "DONE: $OUT.tar.gz"
EOF