-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfpga_upgrade
executable file
·95 lines (76 loc) · 3.13 KB
/
fpga_upgrade
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# Configuration
IP1="192.168.40.252"
IP2="192.168.40.253"
BASE_DIR="/disk2/mu2e/mu2e_UEM_firmware/mu2e_UEM_firmware.runs"
DEFAULT_FILE_PATH="${DEFAULT_FILE_PATH:-$BASE_DIR/impl_1/top_fmc228_pcie.bit}"
ORIGINAL_FILE_PATH="${ORIGINAL_FILE_PATH:-$BASE_DIR/impl_1_old/top_fmc228_pcie_default.bit}"
REMOTE_PATH="${REMOTE_PATH:-/upgrade}"
SOCKET_DIR="/tmp/ssh_mux_$USER"
# Functions
check_ip() { ping -c 1 -W 1 "$1" > /dev/null 2>&1; return $?; }
remount_rw() { ssh -o StrictHostKeyChecking=no -o ControlPath="$SOCKET_DIR/%r@%h:%p" -o ForwardX11=no root@$ACTIVE_IP "mount -o remount,rw /"; }
remount_ro() { ssh -o StrictHostKeyChecking=no -o ControlPath="$SOCKET_DIR/%r@%h:%p" -o ForwardX11=no root@$ACTIVE_IP "mount -o remount,ro /"; }
cleanup() {
echo "Cleaning up. Ensuring remote filesystem is read-only..."
remount_ro && echo "Remote filesystem is now read-only."
ssh -O exit -o ControlPath="$SOCKET_DIR/%r@%h:%p" -o ForwardX11=no root@$ACTIVE_IP && echo "SSH connection closed."
rm -rf "$SOCKET_DIR" && echo "Removed socket directory."
}
# Set trap to call cleanup on EXIT
trap cleanup EXIT
# Start Script
echo "Starting the upgrade process..."
# Determine active IP
if check_ip "$IP1"; then
ACTIVE_IP="$IP1"
elif check_ip "$IP2"; then
ACTIVE_IP="$IP2"
else
echo "Neither IP is reachable. Exiting."
exit 1
fi
echo "Using active IP: $ACTIVE_IP"
# Establish persistent SSH connection
mkdir -p "$SOCKET_DIR"
ssh -o StrictHostKeyChecking=no -o ForwardX11=no -o ControlMaster=auto -o ControlPath="$SOCKET_DIR/%r@%h:%p" -o ControlPersist=600 root@$ACTIVE_IP "echo 'SSH connection established and persisted.'" || exit 1
# Validate file path
file_path=${1:-$DEFAULT_FILE_PATH}
if [ "$1" == "original" ]; then file_path=$ORIGINAL_FILE_PATH; fi
if [ ! -f "$file_path" ]; then
echo "File '$file_path' does not exist. Exiting."
exit 1
fi
# echo "File '$file_path' validated successfully."
# Remount remote filesystem as writable
if remount_rw; then
echo "Remote filesystem successfully remounted as writable."
else
echo "Failed to remount filesystem as writable. Exiting."
exit 1
fi
# Copy file to remote
if scp -o ControlPath="$SOCKET_DIR/%r@%h:%p" -o ForwardX11=no "$file_path" root@$ACTIVE_IP:$REMOTE_PATH; then
echo "File '$file_path' successfully copied to $REMOTE_PATH on $ACTIVE_IP."
else
echo "Failed to copy file. Exiting."
exit 1
fi
# Remount filesystem as read-only
if remount_ro; then
echo "Remote filesystem successfully remounted as read-only."
else
echo "Failed to remount filesystem as read-only. Please verify manually and fix the filesystem state."
fi
# Run upgrade command
file_name=$(basename "$file_path")
if ssh -o ControlPath="$SOCKET_DIR/%r@%h:%p" -o ForwardX11=no root@$ACTIVE_IP "export PATH=\$PATH:/sbin:/usr/sbin; cd $REMOTE_PATH; echo 'Y' | fpga_upgrade \"$file_name\""; then
echo "Upgrade command executed successfully for file: $file_name."
else
echo "Upgrade command failed. Exiting."
exit 1
fi
read -n 1 -p "Press any key once you see the 'Purdue debug monitor 1.00' confirmation in minicom..."
./setup.sh
echo "Completed upgrade. Now starting UDP receiver."
./udp-recv