From 4ce4d6c62ec38845ae69560039c3ad96b1947d2e Mon Sep 17 00:00:00 2001 From: ETWen Date: Wed, 23 Sep 2026 14:43:28 +0800 Subject: [PATCH] feat(temp): Add DDR5 DIMM and hot-swap controller temperatures to PMON ddr5_temp.sh reads the SPD5118 hub on each DDR5 DIMM (i2c bus 5, 0x50/0x51, register 0x31: bit[12:2], sign bit 12, 0.25 C/LSB). A failed read prints 'read fail' instead of a number. Bus and addresses can be passed as arguments. hsc_temp_readback.sh reads the LTC4287 hot-swap controllers on i2c bus 28: HSC_MAIN @ 0x40 and HSC_STBY @ 0x45, internal and external sensor each, selected through 0xF3 and read from 0x8D (Kelvin). v1.0.1 adds the header, corrects the delay comments (DELAY is 0.5 s, not 100 ms) and converts the file from CRLF to LF - CRLF fails outright under bash on SONiC. utils/setup_pmon.ttl calls both right after 'show platform temperature'. It is shared, so every PMON snapshot gets them: Script A's baseline, each Script B soak round, Script C, the Script 4 loop and every Script 5 check point. hsc_temp_readback.sh adds ~4 s to each snapshot. Both are called by path and need the exec bit on the DUT. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01UniUXkxgCG2Ty74advL8Pd --- .../Blanton_Script/ddr5_temp.sh | 34 ++++++++++ .../Blanton_Script/hsc_temp_readback.sh | 65 +++++++++++++++++++ src/Script_ABC_Blanton/utils/setup_pmon.ttl | 4 ++ 3 files changed, 103 insertions(+) create mode 100644 src/Script_ABC_Blanton/Blanton_Script/ddr5_temp.sh create mode 100644 src/Script_ABC_Blanton/Blanton_Script/hsc_temp_readback.sh diff --git a/src/Script_ABC_Blanton/Blanton_Script/ddr5_temp.sh b/src/Script_ABC_Blanton/Blanton_Script/ddr5_temp.sh new file mode 100644 index 0000000..c3c866a --- /dev/null +++ b/src/Script_ABC_Blanton/Blanton_Script/ddr5_temp.sh @@ -0,0 +1,34 @@ +#!/bin/bash +#============================================================================== +# Author : ETWen +# Date : 20260923 +# Purpose : Read DDR5 DIMM temperature from SPD5118 hub (MR49/MR50 @ 0x31) +# Usage : ./ddr5_temp_V1.0.1.sh [bus] [addr ...] +# default: bus=5, addr=0x50 0x51 +# +# Version History: +# V1.0.0 20260923 Initial Version +# V1.0.1 20260923 Output label "DDR temp" +#============================================================================== + +BUS=${1:-5} +shift 2>/dev/null +ADDRS=("$@") +[[ ${#ADDRS[@]} -eq 0 ]] && ADDRS=(0x50 0x51) + +REG_TEMP=0x31 + +for ADDR in "${ADDRS[@]}"; do + raw=$(i2cget -y "$BUS" "$ADDR" "$REG_TEMP" w 2>&1) + if [[ $? -ne 0 || ! $raw =~ ^0x[0-9a-fA-F]+$ ]]; then + echo "[bus $BUS $ADDR] read fail: $raw" + continue + fi + + # bit[12:2] = temperature, bit12 = sign, 0.25 C/LSB + v=$(( (raw >> 2) & 0x7FF )) + (( v & 0x400 )) && v=$(( v - 0x800 )) + + awk -v b="$BUS" -v a="$ADDR" -v r="$raw" -v v="$v" \ + 'BEGIN { printf "[bus %s %s] DDR temp: %.2f C (raw=%s)\n", b, a, v * 0.25, r }' +done diff --git a/src/Script_ABC_Blanton/Blanton_Script/hsc_temp_readback.sh b/src/Script_ABC_Blanton/Blanton_Script/hsc_temp_readback.sh new file mode 100644 index 0000000..bb8228d --- /dev/null +++ b/src/Script_ABC_Blanton/Blanton_Script/hsc_temp_readback.sh @@ -0,0 +1,65 @@ +#!/bin/bash +#============================================================================== +# Author : ETWen +# Date : 20260923 +# Purpose : Read LTC4287 hot-swap controller temperatures (HSC_MAIN / HSC_STBY) +# Select source via 0xF3 (0xEB internal / 0xEF external), then read +# READ_TEMPERATURE 0x8D (Kelvin) and convert to Celsius +# Usage : ./hsc_temp_readback.sh +# bus = BUS (28), HSC_MAIN @ 0x40, HSC_STBY @ 0x45 +# +# Version History: +# V1.0.0 20260922 Initial Version +# V1.0.1 20260923 Add header; fix delay comments (DELAY is 0.5 s, not 100 ms); +# CRLF -> LF (CRLF breaks bash on SONiC) +#============================================================================== + +BUS=28 +DELAY=0.5 # seconds between I2C transactions; ~4 s per run (4 readings x 2) + +read_temp() { + local addr="$1" + local name="$2" + local sel="$3" + + # Select temperature source + i2ctransfer -f -y "$BUS" w3@"$addr" 0xF3 "$sel" 0x00 > /dev/null + + # DELAY between I2C transactions + sleep "$DELAY" + + # Read temperature register 0x8D + raw=$(i2cget -f -y "$BUS" "$addr" 0x8D w 2>/dev/null) + + if [ -z "$raw" ]; then + printf "%-32s : READ ERROR\n" "$name" + sleep "$DELAY" + return + fi + + # Remove 0x prefix and convert hexadecimal to decimal + raw_dec=$((16#${raw#0x})) + + # LTC4287 temperature is in Kelvin + temp_c=$(awk "BEGIN {printf \"%.2f\", $raw_dec - 273.15}") + + printf "%-32s : %8s °C (raw %s)\n" \ + "$name" "$temp_c" "$raw" + + # DELAY before next I2C transaction + sleep "$DELAY" +} + +echo "==========================================================" +echo " LTC4287 Temperature Readback" +echo "==========================================================" + +# HSC_MAIN - LTC4287 @ 0x40 +read_temp 0x40 "HSC_MAIN Internal (PU11)" 0xEB +read_temp 0x40 "HSC_MAIN External (PQ1)" 0xEF + +# HSC_STBY - LTC4287 @ 0x45 +read_temp 0x45 "HSC_STBY Internal (PU46)" 0xEB +read_temp 0x45 "HSC_STBY External (PQ53)" 0xEF + +echo "==========================================================" diff --git a/src/Script_ABC_Blanton/utils/setup_pmon.ttl b/src/Script_ABC_Blanton/utils/setup_pmon.ttl index 3f4f24b..00593f5 100644 --- a/src/Script_ABC_Blanton/utils/setup_pmon.ttl +++ b/src/Script_ABC_Blanton/utils/setup_pmon.ttl @@ -5,6 +5,10 @@ sendln "show platform fan" wait prompt_sonic_root sendln "show platform temperature" wait prompt_sonic_root +sendln "~/Blanton_Script/ddr5_temp.sh" +wait prompt_sonic_root +sendln "~/Blanton_Script/hsc_temp_readback.sh" +wait prompt_sonic_root sendln "show platform psustatus" wait prompt_sonic_root sendln "show platform voltage"