-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathodm_pf_driver_prestart.sh
executable file
·37 lines (31 loc) · 1.11 KB
/
odm_pf_driver_prestart.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# SPDX-License-Identifier: Marvell-MIT
# Copyright (c) 2024 Marvell.
FLAG_FILE="/var/run/uuid_generated"
CFG_FILE="/etc/odm_pf_driver.cfg"
PCI_DEVICE="0000:08:00.0"
DRIVER="vfio-pci"
UUID_LINE="UUID="
# Check if uuidgen is available
command -v uuidgen >/dev/null 2>&1 || { echo "uuid isn't installed"; exit 127; }
# Check if the UUID has already been generated
if [ ! -f "$FLAG_FILE" ]; then
# Generate a new UUID
NEW_UUID=$(uuidgen)
echo "Generated UUID: $NEW_UUID"
# Update the target file with the new UUID
if grep -q "^$UUID_LINE" "$CFG_FILE"; then
# Replace the existing UUID line
sed -i "s/^$UUID_LINE.*/$UUID_LINE$NEW_UUID/" "$CFG_FILE"
else
# Append the UUID line if it doesn't exist
echo "$UUID_LINE$NEW_UUID" >> "$CFG_FILE"
fi
# Create the flag file to indicate the UUID has been generated
touch "$FLAG_FILE"
fi
echo "Unbinding PCI device $PCI_DEVICE"
echo $PCI_DEVICE > /sys/bus/pci/devices/$PCI_DEVICE/driver/unbind
echo "Binding PCI device $PCI_DEVICE to driver $DRIVER"
echo "177d a08b" > /sys/bus/pci/drivers/vfio-pci/new_id
exit 0