Daniel Hsu | 0931b60 | 2024-06-13 13:56:03 +0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Set mctpi2c link up and assign local address. |
| 4 | localEid=8 |
| 5 | busNum=9 |
| 6 | maxRetries=5 |
| 7 | retryInterval=1 |
| 8 | |
| 9 | retry_command() { |
| 10 | |
| 11 | command="$1" |
| 12 | retries=0 |
| 13 | |
| 14 | while [ $retries -lt $maxRetries ]; do |
| 15 | if bash -c "$command"; then |
| 16 | return 0 |
| 17 | else |
| 18 | retries=$((retries + 1)) |
| 19 | echo "Retry $retries/$maxRetries: Command failed. Retrying in $retryInterval seconds..." |
| 20 | sleep $retryInterval |
| 21 | fi |
| 22 | done |
| 23 | |
| 24 | return 1 |
| 25 | } |
| 26 | |
| 27 | # Retry mctp link command |
| 28 | if ! retry_command "mctp link set mctpi2c${busNum} up"; then |
| 29 | echo "Failed to set mctp link after $maxRetries attempts." |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | # Check if local EID is already set |
| 34 | mctpOutput=$(mctp address show) |
| 35 | if echo "$mctpOutput" | grep -q "mctpi2c${busNum}"; then |
| 36 | echo "mctpi2c${busNum} local EID already set" |
| 37 | else |
| 38 | # Retry mctp addr add command |
| 39 | if ! retry_command "mctp addr add ${localEid} dev mctpi2c${busNum}"; then |
| 40 | echo "Failed to add mctp address after $maxRetries attempts." |
| 41 | exit 1 |
| 42 | fi |
| 43 | fi |
| 44 | echo "mctpi2c${busNum} local EID set to ${localEid}" |
| 45 | exit 0 |