blob: f57de01ce510fe23413e280ac1bda3f40114bbe9 [file] [log] [blame]
Lei YU9526acb2020-09-04 17:04:32 +08001#!/bin/bash
2
3set -e
4
5# Get time from ME via ipmb
6# The last 4 bytes are the epoch time, e.g.
7# (iyyyyay) 0 11 0 72 0 4 18 169 82 95
8ret=$(busctl call xyz.openbmc_project.Ipmi.Channel.Ipmb "/xyz/openbmc_project/Ipmi/Channel/Ipmb" org.openbmc.Ipmb sendRequest yyyyay 0x01 0x0a 0x00 0x48 0)
9
10IFS=' ' read -r -a a <<< "${ret}"
11
12if [ "${a[1]}" -ne 0 ]
13then
14 echo "Failed to get time from ME: ${ret}"
15 exit 1
16fi
17
Patrick Williams58826712023-04-14 08:51:37 -050018t0=$((a[7]))
19t1=$((a[8]*256))
20t2=$((a[9]*256*256))
21t3=$((a[10]*256*256*256))
22t=$((t0+t1+t2+t3))
Lei YU9526acb2020-09-04 17:04:32 +080023echo "Setting date to ${t}"
24
25date -s @${t}