summaryrefslogtreecommitdiff
path: root/meta-fii/meta-kudo/recipes-kudo/kudo-sys-utility/kudo-cmd/kudo.sh
blob: 03adb8ef6d14282bc7f45aa13265491711e9417e (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/bash
# help information

source /usr/sbin/kudo-lib.sh

function usage_rst() {
  echo " kudo rst [parameter]"
  echo "        hotswap  --> reset the whole kudo node"
  echo "        system   --> reset the host"
  echo "        btn      --> trigger a power button event"
  echo "        shutdown --> send out shutdown signal to CPU"
  echo "        display  --> "
}

function usage_led() {
  echo " kudo led 'att'/'boot' [parameter]"
  echo "        on --> change to CPU console"
  echo "        off --> change to CPU 0 SCP console"
  echo "        status --> change to CPU 1 SCP console"
}

function usage_uart() {
  echo " kudo uart [parameter]"
  echo "        host --> show CPU console"
  echo "        scp --> show SCP0 console"
  echo "        swhost --> change to CPU console to ttyS1"
  echo "        swscp1 --> change to CPU 0 SCP console to ttyS3"
  echo "        swscp2 --> change to CPU 1 SCP console"
  echo "        swhosthr --> change CPU console to header"
  echo "        swscphr --> change SCP console to header"
  echo "        display  --> "
}

function usage() {
  echo " kudo BMC console system utilities"
  echo " kudo [optional] [parameter]"
  echo "   rst   --> reset traget device"
  echo "   fw    --> get version"
  echo "   uart  --> control the uart mux"
  echo "   led   --> control the leds"
}

function reset() {
  case $1 in
    hotswap)
      # Virtual reset #94
      set_gpio_ctrl 94 out 1
      ;;
    system)
      # S0 system reset #65
      set_gpio_ctrl 65 out 0
      sleep 1
      set_gpio_ctrl 65 out 1
      ;;
    btn)
      # power button #203
      set_gpio_ctrl 203 out 1
      sleep 1
      set_gpio_ctrl 203 out 0
      ;;
    shutdown)
      # BMC_CPU_SHD_REQ #70
      set_gpio_ctrl 70 out 0
      sleep 3
      set_gpio_ctrl 70 out 1
      ;;
    forceOff)
      # power button #203
      set_gpio_ctrl 203 out 1
      sleep 6
      set_gpio_ctrl 203 out 0
      ;;
    display)
      echo "Virtual reset   #94" $(get_gpio_ctrl 94)
      echo "S0 System reset #65" $(get_gpio_ctrl 65)
      echo "Power Button   #203" $(get_gpio_ctrl 203)
      echo "BMC_CPU SHD Req #70" $(get_gpio_ctrl 70)
      ;;
    *)
      usage_rst
    ;;
  esac
}

function fw_rev() {
  BMC_CPLD_VER_FILE="/run/cpld0.version"
  MB_CPLD_VER_FILE="/run/cpld1.version"

  cmd=$(cat $BMC_CPLD_VER_FILE)
  echo " BMC_CPLD: " $cmd
  cmd=$(cat $MB_CPLD_VER_FILE)
  echo " MB_CPLD: " $cmd

  cmd=$(cat /etc/os-release | grep VERSION -w | cut -d '=' -f 2)
  echo " BMC        : " ${cmd}

  #BMC PWR Sequencer
  i2cset -y -f -a 14 0x59 0xfe 0x0000 w
  cmd=$(i2cget -y -f -a 14 0x59 0xfe i 2 | awk '{print substr($0,3)}')
  echo " BMC PowerSequencer : ${cmd}"
  #only display with smbios exists
  if [[ -e /var/lib/smbios/smbios2 ]]; then
    cmd=$(busctl introspect xyz.openbmc_project.Smbios.MDR_V2 \
            /xyz/openbmc_project/inventory/system/chassis/motherboard/bios | grep Version | awk '{print $4}')
    echo " Bios: $cmd"
  fi

  cmd=$(i2cget -f -y 2 0x4f 0x1 w);
  echo " SCP Firmware: ${cmd}"

  adm1266_ver  | grep REVISION

}

function uartmux() {
  case $1 in
    host)
      if [ `tty` ==  "/dev/ttyS0" ]; then
        echo "Couldn't redirect to the host console within BMC local console"
      else
        echo "Entering Console use 'shift ~~..' to quit"
        obmc-console-client -c /etc/obmc-console/server.ttyS1.conf
      fi
      ;;
    scp)
      if [ `tty` ==  "/dev/ttyS0" ]; then
        echo "Couldn't redirect to the scp console within BMC local console"
      else
        echo "Entering Console use 'shift ~~..' to quit"
        obmc-console-client -c /etc/obmc-console/server.ttyS3.conf
      fi
      ;;
    swhost)
      set_gpio_ctrl 167 out 1
      ;;
    swscp1)
      set_gpio_ctrl 161 out 1
      set_gpio_ctrl 177 out 1
      set_gpio_ctrl 198 out 0
      ;;
    swscp2)
      set_gpio_ctrl 161 out 1
      set_gpio_ctrl 177 out 1
      set_gpio_ctrl 198 out 1
      ;;
    swhosthr)
      set_gpio_ctrl 167 out 0
      ;;
    swscphr)
      set_gpio_ctrl 161 out 0
      set_gpio_ctrl 177 out 0
      ;;
    display)
      if [ $(get_gpio_ctrl 167) -eq 1 ]; then
        echo " CPU host to BMC console"
      else
        echo " CPU host to header"
      fi
      if [ $(get_gpio_ctrl 161) -eq 1 ] && [ $(get_gpio_ctrl 177) -eq 1 ]; then
        if [ $(get_gpio_ctrl 198) -eq 1 ]; then
          echo " SCP2 host to BMC console"
        else
          echo " SCP1 host to BMC console"
        fi
      elif [ $(get_gpio_ctrl 161) -eq 0 ] && [ $(get_gpio_ctrl 177) -eq 0 ]; then
        if [ $(get_gpio_ctrl 198) -eq 1 ]; then
          echo " SCP2 host to Header"
        else
          echo " SCP1 host to Header"
        fi
      else
        echo "It's unknown status"
        echo "167" $(get_gpio_ctrl 167)
        echo "161" $(get_gpio_ctrl 161)
        echo "177" $(get_gpio_ctrl 177)
        echo "198" $(get_gpio_ctrl 198)
      fi
      ;;
    *)
      usage_uart
      ;;
  esac
}

function ledtoggle() {

    CurrentLED=$( i2cget -y -f -a 34 0x76 0x05 i 1 | cut -d ' ' -f 2)
  case $1 in
    boot)
        cmd=$((($CurrentLED & 0x40) != 0))
        case $2 in
         on)
            #turn on LED
            if [[ $cmd -eq 0 ]]; then
                setValue=$(( 0x40 + $CurrentLED ))
                i2cset -y -f -a 34 0x76 0x10 $setValue
            fi
            ;;
         off)
            #turn off led
            if [[ $cmd -eq 1 ]]; then
                setValue=$(( 0x80 & $CurrentLED ))
                i2cset -y -f -a 34 0x76 0x10 $setValue
            fi
            ;;
        toggle)
            #turn on LED
                setValue=$(( 0x40 ^ $CurrentLED ))
                i2cset -y -f -a 34 0x76 0x10 $setValue
            ;;
         status)
            #displayLED status
            if [[ $cmd -eq 1 ]]; then
                echo "on"
            else
                echo "off"
            fi
            ;;
         *)
            usage_led
            ;;
        esac
      ;;
    att)
        cmd=$((($CurrentLED & 0x80) != 0))
        case $2 in
         on)
            #turn on LED
            if [[ $cmd -eq 0 ]]; then
                setValue=$(( 0x80 + $CurrentLED ))
                i2cset -y -f -a 34 0x76 0x10 $setValue
            fi
            ;;
         off)
            #turn off led
            if [[ $cmd -eq 1 ]]; then
                 setValue=$(( 0x40 & $CurrentLED ))
                i2cset -y -f -a 34 0x76 0x10 $setValue
            fi
            ;;
        toggle)
            #turn on LED
            setValue=$(( 0x80 ^ $CurrentLED ))
            i2cset -y -f -a 34 0x76 0x10 $setValue
            ;;
         status)
            #displayLED status
            if [[ $cmd -eq 1 ]]; then
                echo "on"
            else
                echo "off"
            fi
            ;;
         *)
            usage_led
            ;;
        esac
      ;;
    *)
        usage_led
        ;;
    esac
}

function usblist() {
  for i in {0..8}
  do
    cmd="devmem 0xf083"$i"154"
    printf "udc%d : 0xF803%d154-" "$i" "$i"
    $cmd
   done
}

case $1 in
  rst)
    reset $2
    ;;
  fw)
    fw_rev
    ;;
  uart)
    uartmux $2
    ;;
  usb)
    usblist
    ;;
  led)
    ledtoggle $2 $3
    ;;
  *)
    usage
    ;;
esac