blob: 0937a9fb8c592b6cee12f7a4dcd7bc922c16f0c6 [file] [log] [blame]
George Hunga0ae66a2020-06-30 10:47:30 +08001#!/bin/bash
2
George Hung89f2ff22021-03-25 13:59:12 +08003MARGIN_TABLE_FILE_IN="/usr/share/read-margin-temp/config-margin.json.in"
4TEMP_FILE="$(mktemp)"
5cp "$MARGIN_TABLE_FILE_IN" "$TEMP_FILE"
George Hunga0ae66a2020-06-30 10:47:30 +08006
George Hung89f2ff22021-03-25 13:59:12 +08007target_num="$(cat $TEMP_FILE | grep '"target"' | wc -l)"
George Hunga0ae66a2020-06-30 10:47:30 +08008
9# wait target dbus
George Hung89f2ff22021-03-25 13:59:12 +080010for ((i = 0; i < ${target_num}; i++)); do
George Hunga0ae66a2020-06-30 10:47:30 +080011 line_num=$((i+1))
George Hung89f2ff22021-03-25 13:59:12 +080012 path="$(cat $TEMP_FILE | grep '"target"' | head -n ${line_num} | tail -n +${line_num} | cut -d '"' -f 4)"
George Hunga0ae66a2020-06-30 10:47:30 +080013 mapper wait $path
14done
15
George Hung027c0552021-03-08 16:45:06 +080016nvmePath="/xyz/openbmc_project/sensors/temperature/nvme"
17nvmeInventoryPath="/xyz/openbmc_project/inventory/system/chassis/motherboard/nvme"
George Hungb3464d02021-04-08 07:36:01 +080018nvmeList=""
George Hung027c0552021-03-08 16:45:06 +080019# Get and Set WCTEMP
20for ((i = 0; i < 16; i++)); do
George Hung89f2ff22021-03-25 13:59:12 +080021 name="@WCTemp$(printf "%02d" $i)@"
George Hung027c0552021-03-08 16:45:06 +080022 wcTemp=72000
George Hungb3464d02021-04-08 07:36:01 +080023 presentState="$(busctl get-property \
George Hung027c0552021-03-08 16:45:06 +080024 xyz.openbmc_project.Inventory.Manager \
25 ${nvmeInventoryPath}${i} \
26 xyz.openbmc_project.Inventory.Item \
George Hungb3464d02021-04-08 07:36:01 +080027 Present | awk '{print $2}')"
George Hung027c0552021-03-08 16:45:06 +080028
George Hungb3464d02021-04-08 07:36:01 +080029 if [[ "$presentState" == "true" ]]; then
Brandon Kimb7f1ec62021-04-19 15:18:10 -070030 actualWCTemp=0
31 for ((j = 0; j < 3; j++)); do
32 actualWCTemp="$(
33 busctl get-property xyz.openbmc_project.nvme.manager \
34 ${nvmePath}${i} \
35 xyz.openbmc_project.Sensor.Threshold.Critical \
36 CriticalHigh | awk '{print $2}'
37 )"
38 if [[ "${actualWCTemp}" -ne 0 ]]; then
39 break
40 fi
41
42 echo "${nvmePath}${i} WCTemp was read to be 0, retrying after 1 sec sleep"
43 sleep 1
44 done
45
Brandon Kim5fb47102021-04-20 14:17:49 -070046 if [[ "${actualWCTemp}" -ne 0 ]]; then
47 wcTemp="$((actualWCTemp * 1000))"
48 else
49 echo "${nvmePath}${i} WCTemp was read to be 0, using default WCTemp: ${wcTemp}"
Brandon Kimb7f1ec62021-04-19 15:18:10 -070050 fi
51
George Hungb3464d02021-04-08 07:36:01 +080052 if [[ -z "$nvmeList" ]]; then
53 nvmeList="\"nvme"${i}"\""
54 else
55 nvmeList="${nvmeList}"", \"nvme"${i}"\""
56 fi
George Hung027c0552021-03-08 16:45:06 +080057 fi
58
George Hungb3464d02021-04-08 07:36:01 +080059 sed -i "s/$name/${wcTemp}/g" "$TEMP_FILE"
George Hung027c0552021-03-08 16:45:06 +080060done
61
George Hungb3464d02021-04-08 07:36:01 +080062sed -i "s/@nvmeList@/${nvmeList}/g" "$TEMP_FILE"
63
George Hung89f2ff22021-03-25 13:59:12 +080064# Use shell parameter expansion to trim the ".in" suffix
65mv "$TEMP_FILE" "${MARGIN_TABLE_FILE_IN%".in"}"
66
George Hunga0ae66a2020-06-30 10:47:30 +080067# start read margin temp
68/usr/bin/read-margin-temp &
69
70exit 0