diff mbox series

[v1,1/1] board/nvidia/bf3: set eth names according to doc

Message ID 20241110184324.50580-2-vjardin@free.fr
State New
Headers show
Series nvidia/bf3 - fix eth names | expand

Commit Message

Vincent Jardin Nov. 10, 2024, 6:43 p.m. UTC
Set the names of the Ethernet interfaces that are exposed from a first
boot so they are aligned with those described by Mellanox/NVIDIA
documentation for the BF3.

Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
 .../bf3/rootfs_overlay/etc/init.d/S04ifnames  | 61 +++++++++++++++++++
 configs/nvidia_bf3_defconfig                  |  3 +
 2 files changed, 64 insertions(+)
 create mode 100755 board/nvidia/bf3/rootfs_overlay/etc/init.d/S04ifnames
diff mbox series

Patch

diff --git a/board/nvidia/bf3/rootfs_overlay/etc/init.d/S04ifnames b/board/nvidia/bf3/rootfs_overlay/etc/init.d/S04ifnames
new file mode 100755
index 0000000000..adb43f1e2c
--- /dev/null
+++ b/board/nvidia/bf3/rootfs_overlay/etc/init.d/S04ifnames
@@ -0,0 +1,61 @@ 
+#!/bin/sh
+# Rename the board's interfaces according to Mellanox/NVIDIA's documentation
+
+rename_interface() {
+    bus_info=$1
+    new_name=$2
+    alt_name=$3
+
+    # Find the current interface name based on bus-info
+    iface=$(find /sys/class/net -type l -exec sh -c '
+        for i; do
+            [ "$(basename "$(readlink -f "$i"/device)")" = "$0" ] && basename "$i"
+        done
+    ' "$bus_info" {} +)
+
+    # Rename the interface if found
+    if [ -n "$iface" ]; then
+        ip link set "$iface" name "$new_name"
+        printf "%s to %s" "$iface" "$new_name"
+
+        # Set altname if provided
+        if [ -n "$alt_name" ]; then
+            ip link property add dev "$new_name" altname "$alt_name"
+            printf "/%s" "$alt_name"
+        fi
+        printf "; "
+    else
+        echo "$bus_info not found"
+    fi
+}
+
+case "$1" in
+    start)
+        printf "Starting interface renaming:"
+        # Initialize success flag
+        rename_allok=0
+        rename_interface "0000:03:00.0" "p0" "enp3s0f0np0" || rename_allok=1
+        rename_interface "0000:03:00.1" "p1" "enp3s0f1np1" || rename_allok=1
+        rename_interface "MLNXBF17:00" "oob_net0" "enamlnxbf17i0" || rename_allok=1
+        rename_interface "virtio1" "tmfifo_net0" || rename_allok=1
+
+	if [ "$rename_allok" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+        ;;
+    stop)
+        ;;
+    restart)
+        # Optional: Handle restart by calling start after stop
+        $0 stop
+        $0 start
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart}"
+        exit 1
+        ;;
+esac
+
+exit 0
diff --git a/configs/nvidia_bf3_defconfig b/configs/nvidia_bf3_defconfig
index 3f958c0062..c5b00aae83 100644
--- a/configs/nvidia_bf3_defconfig
+++ b/configs/nvidia_bf3_defconfig
@@ -10,3 +10,6 @@  BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/nvidia/bf3/linux.config"
 BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
 BR2_TARGET_ROOTFS_INITRAMFS=y
 # BR2_TARGET_ROOTFS_TAR is not set
+BR2_ROOTFS_OVERLAY="board/nvidia/bf3/rootfs_overlay"
+BR2_PACKAGE_LIBMNL=y
+BR2_PACKAGE_IPROUTE2=y