jme: Update CHANGELOG
[jme.git] / scripts / jme_eeprom.sh
CommitLineData
86793c7e
GFT
1#!/bin/bash
2
3########################################
4# Getting eeprom data #
5########################################
6
7# Check bash version
8msg="Please use bash version 3 or later."
9if [[ ${BASH_VERSION} =~ ^([0-9])\.[0-9]\.(.*) ]]; then
10 if (( ${BASH_REMATCH[1]} < 3 )); then
11 echo ${msg}
12 exit
13 fi
14else
15 echo ${msg}
16 exit
17fi
18
19# Parse arguments
20if [[ ! $1 =~ ^eth[0-9]$ ]]; then
21 echo "Usage: $0 ethX"
22 echo
23 echo "Print eeprom info of JME Ethernet."
24 echo
25 exit
26fi
27
28# Get eeprom data via ethtool
29PATH="${PATH}:/sbin:/usr/sbin:/bin:/usr/bin"
30romdata=$(ethtool -e $1 raw on |\
31 od --width=1 --format=x1 --address-radix=x --output-duplicates |\
32 awk '{print $2;}')
33if [[ -z "${romdata}" ]]; then
34 exit
35fi
36romdata=$(echo ${romdata} | tr '[:lower:]' '[:upper:]' | sed 's/\( FF\)\+$//')
37
38########################################
39# Check for all non-optional data #
40########################################
41
42# Check JME eeprom prefix
43echo -n "EEPROM prefix check: "
44if [[ ${romdata} =~ ^55\ AA\ (.*)$ ]]; then
45 echo OK.
46else
47 echo "Failed. (Not JMicron NIC?)"
48 exit
49fi
50romdata=${BASH_REMATCH[1]}
51
52# Check JME eeprom suffix
53echo -n "EEPROM suffix check: "
54if [[ ${romdata} =~ ^(.*)\ 80\ 00\ 00$ ]]; then
55 echo OK.
56else
57 echo "Failed (Not JMicron NIC?)."
58 exit
59fi
60romdata=${BASH_REMATCH[1]}
61
62# Check JME eeprom MAC Address
63echo -n "EEPROM MAC Address check: "
64if [[ ${romdata} =~ ^(.*)[\ ]?01\ 38\ ([0-9A-F]{2})\ 01\ 39\ ([0-9A-F]{2})\ 01\ 3A\ ([0-9A-F]{2})\ 01\ 3B\ ([0-9A-F]{2})\ 01\ 3C\ ([0-9A-F]{2})\ 01\ 3D\ ([0-9A-F]{2})[\ ]?(.*)$ ]]; then
65 echo OK.
66 MACADDR=${BASH_REMATCH[2]}:${BASH_REMATCH[3]}:${BASH_REMATCH[4]}:${BASH_REMATCH[5]}:${BASH_REMATCH[6]}:${BASH_REMATCH[7]}
67 echo " MAC Address: ${MACADDR}"
68else
69 echo Failed.
70 exit
71fi
72romdata="${BASH_REMATCH[1]} ${BASH_REMATCH[8]}"
73
74########################################
75# Print out all optional data #
76########################################
77
78if [[ -z "${romdata}" ]]; then
79 exit
80fi
81
82# Print other eeprom data
83(( smicmd = 0 ))
84echo -e "\nOther eeprom data:"
85while [[ ! -z "${romdata}" ]]; do
86 if [[ ! ${romdata} =~ ^[\ ]?(0[012])\ ([0-9A-F]{2})\ ([0-9A-F]{2})[\ ]?(.*) ]]; then
87 echo " EEPROM contains error data"
88 exit
89 fi
90 cmd=${BASH_REMATCH[1]}
91 address=${BASH_REMATCH[2]}
92 value=${BASH_REMATCH[3]}
93 romdata=${BASH_REMATCH[4]}
94
95 if [[ (( ${smicmd} == 0 )) && ${cmd} == "01" && ${address} == "53" ]]; then
96 (( ++smicmd )); v1=${value}
97 elif [[ (( ${smicmd} == 1 )) && ${cmd} == "01" && ${address} == "52" ]]; then
98 (( ++smicmd )); v2=${value}
99 elif [[ (( ${smicmd} == 2 )) && ${cmd} == "01" && ${address} == "51" ]]; then
100 (( ++smicmd )); v3=${value}
101 elif [[ (( ${smicmd} == 3 )) && ${cmd} == "01" && ${address} == "50" ]]; then
102 (( smicmd = 0 ))
103 v4=${value}
104 data=${v1}${v2}
105 bcenv="scale = 0; obase = 10; ibase = 16;"
106 reg=$(echo "${bcenv} ${v3} / 8;" | bc)
107 phy=$(echo "${bcenv} a = ${v3}; b = ${v4};\
108 a %= 4; a *= 8; b /= 40; a + b;" | bc)
109 rw=$(echo "${bcenv} a = ${v4}; a /= 20; a % 2;" | bc)
110 if [[ ${rw} == "1" ]]; then
111 rw="Write"
112 value=" value=${data}"
113 else
114 rw="Read"
115 value=""
116 fi
117 valid=$(echo "${bcenv} a = ${v4}; a % 20;" | bc)
118 if [[ ${valid} == "16" ]]; then
119 valid="Valid"
120 else
121 valid="Invalid"
122 fi
123 echo "${valid} SMI Command: ${rw} phyaddr=${phy} reg=${reg}${value}"
124 elif [[ (( ${smicmd} != 0 )) ]]; then
125 echo " EEPROM contains error data"
126 exit
127 else
128 if [[ ${cmd} == "00" ]]; then
129 echo -n "Configuration Space: "
130 elif [[ ${cmd} == "01" ]]; then
131 echo -n "First IO Space(BAR2): "
132 elif [[ ${cmd} == "02" ]]; then
133 echo -n "Second IO Space(BAR3): "
134 fi
135 echo "Address=${address} Value=${value}"
136 fi
137done
138