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