XP Chen | 0e48335 | 2021-05-12 09:44:26 -0500 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # help information |
| 3 | |
| 4 | source /usr/sbin/kudo-lib.sh |
| 5 | |
| 6 | function usage_rst() { |
| 7 | echo " kudo rst [parameter]" |
| 8 | echo " hotswap --> reset the whole kudo node" |
| 9 | echo " system --> reset the host" |
| 10 | echo " btn --> trigger a power button event" |
| 11 | echo " shutdown --> send out shutdown signal to CPU" |
| 12 | echo " display --> " |
| 13 | } |
| 14 | |
| 15 | function usage_led() { |
| 16 | |
| 17 | echo " kudo led 'att'/'boot' [parameter]" |
| 18 | echo " on --> change to CPU console" |
| 19 | echo " off --> change to CPU 0 SCP console" |
| 20 | echo " status --> change to CPU 1 SCP console" |
| 21 | } |
| 22 | |
| 23 | function usage_uart() { |
| 24 | echo " kudo uart [parameter]" |
| 25 | echo " host --> change to CPU console" |
| 26 | echo " scp1 --> change to CPU 0 SCP console" |
| 27 | echo " scp2 --> change to CPU 1 SCP console" |
| 28 | echo " hosthr --> change CPU console to header" |
| 29 | echo " scphr --> change SCP console to header" |
| 30 | echo " display --> " |
| 31 | } |
| 32 | |
| 33 | function usage() { |
| 34 | echo " kudo BMC console system utilities" |
| 35 | echo " kudo [optional] [parameter]" |
| 36 | echo " rst --> reset traget device" |
| 37 | echo " fw --> get version" |
| 38 | echo " uart --> control the uart mux" |
| 39 | echo " led --> control the leds" |
| 40 | } |
| 41 | |
| 42 | function reset() { |
| 43 | case $1 in |
| 44 | hotswap) |
| 45 | # Virtual reset #94 |
| 46 | set_gpio_ctrl 94 out 1 |
| 47 | ;; |
| 48 | system) |
| 49 | # S0 system reset #65 |
| 50 | set_gpio_ctrl 65 out 0 |
| 51 | sleep 1 |
| 52 | set_gpio_ctrl 65 out 1 |
| 53 | ;; |
| 54 | btn) |
| 55 | # power button #203 |
| 56 | set_gpio_ctrl 203 out 1 |
| 57 | sleep 1 |
| 58 | set_gpio_ctrl 203 out 0 |
| 59 | ;; |
| 60 | shutdown) |
| 61 | # BMC_CPU_SHD_REQ #70 |
| 62 | set_gpio_ctrl 70 out 0 |
| 63 | sleep 3 |
| 64 | set_gpio_ctrl 70 out 1 |
| 65 | ;; |
| 66 | forceOff) |
| 67 | # power button #203 |
| 68 | set_gpio_ctrl 203 out 1 |
| 69 | sleep 6 |
| 70 | set_gpio_ctrl 203 out 0 |
| 71 | ;; |
| 72 | display) |
| 73 | echo "Virtual reset #94" $(get set_gpio_ctrl 94) |
| 74 | echo "S0 System reset #65" $(get set_gpio_ctrl 65) |
| 75 | echo "Power Button #203" $(get set_gpio_ctrl 203) |
| 76 | echo "BMC_CPU SHD Req #70" $(get set_gpio_ctrl 70) |
| 77 | ;; |
| 78 | *) |
| 79 | usage_rst |
| 80 | ;; |
| 81 | esac |
| 82 | } |
| 83 | |
| 84 | function fw_rev() { |
| 85 | BMC_CPLD_VER_FILE="/run/cpld0.version" |
| 86 | MB_CPLD_VER_FILE="/run/cpld1.version" |
| 87 | |
| 88 | cmd=$(cat $BMC_CPLD_VER_FILE) |
| 89 | echo " BMC_CPLD: " $cmd |
| 90 | cmd=$(cat $MB_CPLD_VER_FILE) |
| 91 | echo " MB_CPLD: " $cmd |
| 92 | |
| 93 | cmd=$(cat /etc/os-release | grep VERSION -w | cut -d '=' -f 2) |
| 94 | echo " BMC : " ${cmd} |
| 95 | |
| 96 | #BMC PWR Sequencer |
| 97 | i2cset -y -f -a 14 0x59 0xfe 0x0000 w |
| 98 | cmd=$(i2cget -y -f -a 14 0x59 0xfe i 2 | awk '{print substr($0,3)}') |
| 99 | echo " BMC PowerSequencer : ${cmd}" |
| 100 | #only display with smbios exists |
| 101 | if [[ -e /var/lib/smbios/smbios2 ]]; then |
| 102 | cmd=$(busctl introspect xyz.openbmc_project.Smbios.MDR_V2 \ |
| 103 | /xyz/openbmc_project/inventory/system/chassis/motherboard/bios | grep Version | awk '{print $4}') |
| 104 | echo " Bios: $cmd" |
| 105 | fi |
| 106 | |
| 107 | cmd=$(i2cget -f -y 2 0x4f 0x1 w); |
| 108 | echo " SCP Firmware: ${cmd}" |
| 109 | |
| 110 | adm1266_ver | grep REVISION |
| 111 | |
| 112 | } |
| 113 | |
| 114 | function uartmux() { |
| 115 | case $1 in |
| 116 | host) |
| 117 | set_gpio_ctrl 167 out 1 |
| 118 | ;; |
| 119 | scp1) |
| 120 | set_gpio_ctrl 161 out 1 |
| 121 | set_gpio_ctrl 177 out 1 |
| 122 | set_gpio_ctrl 198 out 0 |
| 123 | ;; |
| 124 | scp2) |
| 125 | set_gpio_ctrl 161 out 1 |
| 126 | set_gpio_ctrl 177 out 1 |
| 127 | set_gpio_ctrl 198 out 1 |
| 128 | ;; |
| 129 | hosthr) |
| 130 | set_gpio_ctrl 167 out 0 |
| 131 | ;; |
| 132 | scphr) |
| 133 | set_gpio_ctrl 161 out 0 |
| 134 | set_gpio_ctrl 177 out 0 |
| 135 | ;; |
| 136 | display) |
| 137 | if [ $(get_gpio_ctrl 167) -eq 1 ]; then |
| 138 | echo " CPU host to BMC console" |
| 139 | else |
| 140 | echo " CPU host to header" |
| 141 | fi |
| 142 | if [ $(get_gpio_ctrl 161) -eq 1 ] && [ $(get_gpio_ctrl 177) -eq 1 ]; then |
| 143 | if [ $(get_gpio_ctrl 198) -eq 1 ]; then |
| 144 | echo " SCP2 host to BMC console" |
| 145 | else |
| 146 | echo " SCP1 host to BMC console" |
| 147 | fi |
| 148 | elif [ $(get_gpio_ctrl 161) -eq 0 ] && [ $(get_gpio_ctrl 177) -eq 0 ]; then |
| 149 | if [ $(get_gpio_ctrl 198) -eq 1 ]; then |
| 150 | echo " SCP2 host to Header" |
| 151 | else |
| 152 | echo " SCP1 host to Header" |
| 153 | fi |
| 154 | else |
| 155 | echo "It's unknown status" |
| 156 | echo "167" $(get_gpio_ctrl 167) |
| 157 | echo "161" $(get_gpio_ctrl 161) |
| 158 | echo "177" $(get_gpio_ctrl 177) |
| 159 | echo "198" $(get_gpio_ctrl 198) |
| 160 | fi |
| 161 | ;; |
| 162 | *) |
| 163 | usage_uart |
| 164 | ;; |
| 165 | esac |
| 166 | } |
| 167 | |
| 168 | function ledtoggle() { |
| 169 | |
| 170 | CurrentLED=$( i2cget -y -f -a 34 0x76 0x05 i 1 | cut -d ' ' -f 2) |
| 171 | case $1 in |
| 172 | boot) |
| 173 | cmd=$((($CurrentLED & 0x40) != 0)) |
| 174 | case $2 in |
| 175 | on) |
| 176 | #turn on LED |
| 177 | if [[ $cmd -eq 0 ]]; then |
| 178 | setValue=$(( 0x40 + $CurrentLED )) |
| 179 | i2cset -y -f -a 34 0x76 0x10 $setValue |
| 180 | fi |
| 181 | ;; |
| 182 | off) |
| 183 | #turn off led |
| 184 | if [[ $cmd -eq 1 ]]; then |
| 185 | setValue=$(( 0x80 & $CurrentLED )) |
| 186 | i2cset -y -f -a 34 0x76 0x10 $setValue |
| 187 | fi |
| 188 | ;; |
| 189 | toggle) |
| 190 | #turn on LED |
| 191 | setValue=$(( 0x40 ^ $CurrentLED )) |
| 192 | i2cset -y -f -a 34 0x76 0x10 $setValue |
| 193 | ;; |
| 194 | status) |
| 195 | #displayLED status |
| 196 | if [[ $cmd -eq 1 ]]; then |
| 197 | echo "on" |
| 198 | else |
| 199 | echo "off" |
| 200 | fi |
| 201 | ;; |
| 202 | *) |
| 203 | usage_led |
| 204 | ;; |
| 205 | esac |
| 206 | ;; |
| 207 | att) |
| 208 | cmd=$((($CurrentLED & 0x80) != 0)) |
| 209 | case $2 in |
| 210 | on) |
| 211 | #turn on LED |
| 212 | if [[ $cmd -eq 0 ]]; then |
| 213 | setValue=$(( 0x80 + $CurrentLED )) |
| 214 | i2cset -y -f -a 34 0x76 0x10 $setValue |
| 215 | fi |
| 216 | ;; |
| 217 | off) |
| 218 | #turn off led |
| 219 | if [[ $cmd -eq 1 ]]; then |
| 220 | setValue=$(( 0x40 & $CurrentLED )) |
| 221 | i2cset -y -f -a 34 0x76 0x10 $setValue |
| 222 | fi |
| 223 | ;; |
| 224 | toggle) |
| 225 | #turn on LED |
| 226 | setValue=$(( 0x80 ^ $CurrentLED )) |
| 227 | i2cset -y -f -a 34 0x76 0x10 $setValue |
| 228 | ;; |
| 229 | status) |
| 230 | #displayLED status |
| 231 | if [[ $cmd -eq 1 ]]; then |
| 232 | echo "on" |
| 233 | else |
| 234 | echo "off" |
| 235 | fi |
| 236 | ;; |
| 237 | *) |
| 238 | usage_led |
| 239 | ;; |
| 240 | esac |
| 241 | ;; |
| 242 | *) |
| 243 | usage_led |
| 244 | ;; |
| 245 | esac |
| 246 | } |
| 247 | |
| 248 | function usblist() { |
| 249 | for i in {0..8} |
| 250 | do |
| 251 | cmd="devmem 0xf083"$i"154" |
| 252 | printf "udc%d : 0xF803%d154-" "$i" "$i" |
| 253 | $cmd |
| 254 | done |
| 255 | } |
| 256 | |
| 257 | case $1 in |
| 258 | rst) |
| 259 | reset $2 |
| 260 | ;; |
| 261 | fw) |
| 262 | fw_rev |
| 263 | ;; |
| 264 | uart) |
| 265 | uartmux $2 |
| 266 | ;; |
| 267 | usb) |
| 268 | usblist |
| 269 | ;; |
| 270 | led) |
| 271 | ledtoggle $2 $3 |
| 272 | ;; |
| 273 | *) |
| 274 | usage |
| 275 | ;; |
| 276 | esac |