meta-g220a: Add me-time-sync
g220a BMC needs to get time from ME on start.
Add me-time-sync package that fetches time from ME via ipmb, and set the
time to BMC via `date` command.
Tested: Verify the time is set on BMC boots
(From meta-bytedance rev: c8640d007d25676261acc04317e5612269bd3ed5)
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I0e7f1d249cf743e3477843a67a6d2e6250c43aa6
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/meta-bytedance/meta-g220a/recipes-phosphor/datetime/me-time-sync.bb b/meta-bytedance/meta-g220a/recipes-phosphor/datetime/me-time-sync.bb
new file mode 100644
index 0000000..776bccf
--- /dev/null
+++ b/meta-bytedance/meta-g220a/recipes-phosphor/datetime/me-time-sync.bb
@@ -0,0 +1,20 @@
+SUMMARY = "ME time sync"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+inherit allarch
+inherit obmc-phosphor-systemd
+
+RDEPENDS_${PN} += "bash"
+
+S = "${WORKDIR}"
+
+SRC_URI += "file://me-time-sync.sh"
+
+do_install() {
+ install -d ${D}${bindir}
+ install -m 0755 ${S}/me-time-sync.sh ${D}${bindir}/me-time-sync.sh
+}
+
+SYSTEMD_SERVICE_${PN} += "me-time-sync.service"
diff --git a/meta-bytedance/meta-g220a/recipes-phosphor/datetime/me-time-sync/me-time-sync.service b/meta-bytedance/meta-g220a/recipes-phosphor/datetime/me-time-sync/me-time-sync.service
new file mode 100644
index 0000000..e0ee717
--- /dev/null
+++ b/meta-bytedance/meta-g220a/recipes-phosphor/datetime/me-time-sync/me-time-sync.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Sync time from ME
+Wants=ipmb.service
+After=ipmb.service
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/me-time-sync.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-bytedance/meta-g220a/recipes-phosphor/datetime/me-time-sync/me-time-sync.sh b/meta-bytedance/meta-g220a/recipes-phosphor/datetime/me-time-sync/me-time-sync.sh
new file mode 100644
index 0000000..833b97d
--- /dev/null
+++ b/meta-bytedance/meta-g220a/recipes-phosphor/datetime/me-time-sync/me-time-sync.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+set -e
+
+# Get time from ME via ipmb
+# The last 4 bytes are the epoch time, e.g.
+# (iyyyyay) 0 11 0 72 0 4 18 169 82 95
+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)
+
+IFS=' ' read -r -a a <<< "${ret}"
+
+if [ "${a[1]}" -ne 0 ]
+then
+ echo "Failed to get time from ME: ${ret}"
+ exit 1
+fi
+
+t0=$((${a[7]}))
+t1=$((${a[8]}*256))
+t2=$((${a[9]}*256*256))
+t3=$((${a[10]}*256*256*256))
+t=$((${t0}+${t1}+${t2}+${t3}))
+echo "Setting date to ${t}"
+
+date -s @${t}
diff --git a/meta-bytedance/meta-g220a/recipes-phosphor/images/obmc-phosphor-image.bbappend b/meta-bytedance/meta-g220a/recipes-phosphor/images/obmc-phosphor-image.bbappend
new file mode 100644
index 0000000..a3fecbf
--- /dev/null
+++ b/meta-bytedance/meta-g220a/recipes-phosphor/images/obmc-phosphor-image.bbappend
@@ -0,0 +1,2 @@
+OBMC_IMAGE_EXTRA_INSTALL_append_g220a = " me-time-sync \
+ "