blob: 427c98e9a0cc82f0e467967bc6fb2b7c3d43ebe9 [file] [log] [blame]
George Hunga0ae66a2020-06-30 10:47:30 +08001#!/bin/bash
2
George Hungd7541982021-03-31 15:38:25 +08003FAN_TABLE_FILE_IN="/usr/share/swampd/config.json.in"
4TEMP_FILE="$(mktemp)"
5cp "$FAN_TABLE_FILE_IN" "$TEMP_FILE"
George Hungdf4f8772021-01-20 21:40:31 +08006
George Hunga0ae66a2020-06-30 10:47:30 +08007# wait for fan dbus
8mapper wait /xyz/openbmc_project/sensors/fan_tach/fan0
9mapper wait /xyz/openbmc_project/sensors/fan_tach/fan1
George Hung0a72c0f2020-07-16 13:47:14 +080010mapper wait /xyz/openbmc_project/sensors/fan_tach/fb_fan0
11mapper wait /xyz/openbmc_project/sensors/fan_tach/fb_fan1
12mapper wait /xyz/openbmc_project/sensors/fan_tach/fb_fan2
George Hunga0ae66a2020-06-30 10:47:30 +080013
George Hunga0ae66a2020-06-30 10:47:30 +080014# generate fan table writePath
Patrick Williams8c226232023-04-15 20:05:21 -050015Fan_0_To_4_Hwmon="$(ls /sys/devices/platform/ahb/ahb:*/*pwm-fan-controller/hwmon/)"
George Hunga0ae66a2020-06-30 10:47:30 +080016
George Hungdf4f8772021-01-20 21:40:31 +080017if [[ "$Fan_0_To_4_Hwmon" != "" ]]; then
Patrick Williams8c226232023-04-15 20:05:21 -050018 sed -i "s/@Fan_0_To_4_Hwmon@/$Fan_0_To_4_Hwmon/g" "$TEMP_FILE"
George Hunga0ae66a2020-06-30 10:47:30 +080019fi
20
George Hungbf078822021-06-11 13:23:25 +080021presentGpio=()
22presentState=()
23gpioPath="/sys/class/gpio/gpio"
24if [[ -f "/etc/nvme/nvme_config.json" ]]; then
Patrick Williams8c226232023-04-15 20:05:21 -050025 # shellcheck disable=SC2207
26 presentGpio=($(grep NVMeDrivePresentPin /etc/nvme/nvme_config.json \
George Hungbf078822021-06-11 13:23:25 +080027 | awk '{print $2}' | cut -d "," -f 0))
28fi
29
30nvmePath="/xyz/openbmc_project/sensors/temperature/nvme"
George Hungbf078822021-06-11 13:23:25 +080031# Get and Set WCTEMP
32for ((i = 0; i < 16; i++)); do
33 name="@WCTemp$(printf "%02d" $i)@"
34 wcTemp=72000
35
36 if [[ -d "${gpioPath}${presentGpio[i]}" ]] &&
Patrick Williams8c226232023-04-15 20:05:21 -050037 [[ "$(cat "${gpioPath}${presentGpio[i]}/value")" == "0" ]]; then
George Hungbf078822021-06-11 13:23:25 +080038 presentState[i]="true"
39 else
40 presentState[i]="false"
41 fi
42
43 if [[ "${presentState[i]}" == "true" ]]; then
44 actualWCTemp=0
45 for ((j = 0; j < 3; j++)); do
46 actualWCTemp="$(
47 busctl get-property xyz.openbmc_project.nvme.manager \
48 ${nvmePath}${i} \
49 xyz.openbmc_project.Sensor.Threshold.Critical \
50 CriticalHigh | awk '{print $2}'
51 )"
52 if [[ "${actualWCTemp}" -ne 0 ]]; then
53 break
54 fi
55
56 echo "${nvmePath}${i} WCTemp was read to be 0, retrying after 1 sec sleep"
57 sleep 1
58 done
59
60 if [[ "${actualWCTemp}" -ne 0 ]]; then
61 wcTemp="$(echo "${actualWCTemp} -7" | awk '{printf $1 + $2}')"
62 else
63 echo "${nvmePath}${i} WCTemp was read to be 0, using default WCTemp: ${wcTemp}"
64 fi
65 fi
66
67 sed -i "s/$name/${wcTemp}/g" "$TEMP_FILE"
68
69 if [[ "${presentState[i]}" == "false" ]]; then
70 sensorPath="${nvmePath}${i}"
71 pathLine=$(grep -nw "$sensorPath" "$TEMP_FILE" | awk -F ':' '{print $1}')
72 sed -i "$TEMP_FILE" -re "$((pathLine - 3)),$((pathLine + 6))d"
73 if [ $i -eq 15 ]; then
74 sed -i "$((pathLine - 4))s/,//" "$TEMP_FILE"
75 fi
76
77 listLine=$(grep -n "\"name\": \"nvme${i}\"" "$TEMP_FILE" | awk -F ':' '{print $1}')
78 sed -i "$TEMP_FILE" -re "$((listLine - 1)),$((listLine + 21))d"
79 if [ $i -eq 15 ]; then
80 sed -i "$((listLine - 2))s/,//" "$TEMP_FILE"
81 fi
82 fi
83done
84
George Hungd7541982021-03-31 15:38:25 +080085# Use shell parameter expansion to trim the ".in" suffix
86mv "$TEMP_FILE" "${FAN_TABLE_FILE_IN%".in"}"
87
George Hunga0ae66a2020-06-30 10:47:30 +080088exit 0