Lei YU | 9526acb | 2020-09-04 17:04:32 +0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -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 |
| 8 | ret=$(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 | |
| 10 | IFS=' ' read -r -a a <<< "${ret}" |
| 11 | |
| 12 | if [ "${a[1]}" -ne 0 ] |
| 13 | then |
| 14 | echo "Failed to get time from ME: ${ret}" |
| 15 | exit 1 |
| 16 | fi |
| 17 | |
| 18 | t0=$((${a[7]})) |
| 19 | t1=$((${a[8]}*256)) |
| 20 | t2=$((${a[9]}*256*256)) |
| 21 | t3=$((${a[10]}*256*256*256)) |
| 22 | t=$((${t0}+${t1}+${t2}+${t3})) |
| 23 | echo "Setting date to ${t}" |
| 24 | |
| 25 | date -s @${t} |