summaryrefslogtreecommitdiff
path: root/meta-facebook/meta-harma/recipes-networking/mctp/files/setup-local-eid
blob: a72606fcf2ee29a15af0c9f2fa6caec663742724 (plain)
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
#!/bin/bash

# Set mctpi2c link up and assign local address.
localEid=8
busNum=9
maxRetries=5
retryInterval=1

retry_command() {

    command="$1"
    retries=0

    while [ $retries -lt $maxRetries ]; do
        if bash -c "$command"; then
            return 0
        else
            retries=$((retries + 1))
            echo "Retry $retries/$maxRetries: Command failed. Retrying in $retryInterval seconds..."
            sleep $retryInterval
        fi
    done

    return 1
}

# Retry mctp link command
if ! retry_command "mctp link set mctpi2c${busNum} up"; then
    echo "Failed to set mctp link after $maxRetries attempts."
    exit 1
fi

# Check if local EID is already set
mctpOutput=$(mctp address show)
if echo "$mctpOutput" | grep -q "mctpi2c${busNum}"; then
    echo "mctpi2c${busNum} local EID already set"
else
    # Retry mctp addr add command
    if ! retry_command "mctp addr add ${localEid} dev mctpi2c${busNum}"; then
        echo "Failed to add mctp address after $maxRetries attempts."
        exit 1
    fi
fi
echo "mctpi2c${busNum} local EID set to ${localEid}"
exit 0