-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathoc-list-cards.sh
executable file
·42 lines (36 loc) · 1.61 KB
/
oc-list-cards.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
38
39
40
41
42
#!/bin/bash
#check for lspci
lspci >/dev/null 2>&1
[ $? -ne 0 ] && printf "lspci not found. Please make sure it is installed and can be found in the PATH environment variable.\n" >&2 && exit 1
[ -h $0 ] && package_root=`ls -l "$0" |sed -e 's|.*-> ||'` || package_root="$0"
package_root=$(dirname $package_root)
# find all OC cards in the system
allcards=`ls /dev/ocxl 2>/dev/null | awk -F"." '{ print $2 }' | sed s/$/.0/ | sort`
allcards_array=($allcards)
# only execute if devices were found
if [ ${#allcards_array[@]} -ne 0 ]; then
# print table header
printf "${bold}%-21s %-29s %-29s %-20s %s${normal}\n" "#" "Card" "Flashed" "by" "Last Image"
# print card information and flash history
i=0
while read d ; do
p[$i]=$(cat /sys/bus/pci/devices/${allcards_array[$i]}/subsystem_device)
# prevent error message if there are no information for the card
[ -f /var/ocxl/card$i ] && f=$(cat /var/ocxl/card$i)
while IFS='' read -r line || [[ -n $line ]]; do
if [[ ${line:0:6} == ${p[$i]:0:6} ]]; then
parse_info=($line)
board_vendor[$i]=${parse_info[1]}
fpga_type[$i]=${parse_info[2]}
flash_partition[$i]=${parse_info[3]}
flash_block[$i]=${parse_info[4]}
flash_interface[$i]=${parse_info[5]}
flash_secondary[$i]=${parse_info[6]}
printf "%-20s %-30s %-29s %-20s %s\n" "card$i:${allcards_array[$i]}" "${line:6:21}" "${f:0:29}" "${f:30:20}" "${f:51}"
fi
done < "$package_root/oc-devices"
i=$[$i+1]
done < <( lspci -d "1014":"062b" -s .1 )
else
printf "No OpenCAPI cards found!\n"
fi