1*9526acb2SLei YU#!/bin/bash
2*9526acb2SLei YU
3*9526acb2SLei YUset -e
4*9526acb2SLei YU
5*9526acb2SLei YU# Get time from ME via ipmb
6*9526acb2SLei YU# The last 4 bytes are the epoch time, e.g.
7*9526acb2SLei YU# (iyyyyay) 0 11 0 72 0 4 18 169 82 95
8*9526acb2SLei YUret=$(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*9526acb2SLei YU
10*9526acb2SLei YUIFS=' ' read -r -a a <<< "${ret}"
11*9526acb2SLei YU
12*9526acb2SLei YUif [ "${a[1]}" -ne 0 ]
13*9526acb2SLei YUthen
14*9526acb2SLei YU  echo "Failed to get time from ME: ${ret}"
15*9526acb2SLei YU  exit 1
16*9526acb2SLei YUfi
17*9526acb2SLei YU
18*9526acb2SLei YUt0=$((${a[7]}))
19*9526acb2SLei YUt1=$((${a[8]}*256))
20*9526acb2SLei YUt2=$((${a[9]}*256*256))
21*9526acb2SLei YUt3=$((${a[10]}*256*256*256))
22*9526acb2SLei YUt=$((${t0}+${t1}+${t2}+${t3}))
23*9526acb2SLei YUecho "Setting date to ${t}"
24*9526acb2SLei YU
25*9526acb2SLei YUdate -s @${t}
26