meta-nicole: phosphor-ipmi-config: Set device id

This adds a dev_id.json with Nicole specific values and a systemd unit
which changes at the boot time the device ID in the dev_id.json to the
actual BMC position.

Tested: `ipmitool mc info` now shows the actual BMC position in the
        Device ID field.

(From meta-yadro rev: 8dcdb1ef8661b2f5624d75787bd4bcc4da8301d7)

Change-Id: Ia819ef4154ffe368ca9684662c248295060e0597
Signed-off-by: Alexander Filippov <a.filippov@yadro.com>
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config.bbappend b/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config.bbappend
new file mode 100644
index 0000000..466f42f
--- /dev/null
+++ b/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config.bbappend
@@ -0,0 +1,21 @@
+FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
+
+inherit systemd
+
+RDEPENDS_${PN} = "${VIRTUAL-RUNTIME_base-utils}"
+SYSTEMD_SERVICE_${PN} = "${BPN}.service"
+SRC_URI_append = " \
+    file://${BPN}-set-device-id.sh \
+    file://${BPN}.service \
+"
+
+S = "${WORKDIR}"
+do_install_append() {
+    install -d ${D}${bindir} ${D}${systemd_system_unitdir}
+    install ${BPN}-set-device-id.sh ${D}${bindir}/
+    install -m 0644 ${BPN}.service ${D}${systemd_system_unitdir}/
+}
+
+FILES_${PN}_append = " \
+    ${bindir}/${BPN}-set-device-id.sh \
+"
diff --git a/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config/dev_id.json b/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config/dev_id.json
new file mode 100644
index 0000000..fe51aa6
--- /dev/null
+++ b/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config/dev_id.json
@@ -0,0 +1,8 @@
+{
+    "id": 0,
+    "revision": 1,
+    "addn_dev_support": 0,
+    "manuf_id": 49769,
+    "prod_id": 1,
+    "aux": 0
+}
diff --git a/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config/phosphor-ipmi-config-set-device-id.sh b/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config/phosphor-ipmi-config-set-device-id.sh
new file mode 100755
index 0000000..6600ced
--- /dev/null
+++ b/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config/phosphor-ipmi-config-set-device-id.sh
@@ -0,0 +1,5 @@
+#!/bin/sh -eu
+
+BMCPOS=$(awk -v RS=" " '/^bmcposition=/{print substr($0,13)}' /proc/cmdline)
+sed -r "s/\"id\"\s*:\s*[0-9]+\s*,/\"id\": ${BMCPOS:-0},/" -i \
+    /usr/share/ipmi-providers/dev_id.json
diff --git a/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config/phosphor-ipmi-config.service b/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config/phosphor-ipmi-config.service
new file mode 100644
index 0000000..6471380
--- /dev/null
+++ b/meta-yadro/meta-nicole/recipes-phosphor/ipmi/phosphor-ipmi-config/phosphor-ipmi-config.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Set DeviceID for ipmi-host
+Before=phosphor-ipmi-host.service
+
+[Service]
+Type=oneshot
+TimeoutSec=0
+RemainAfterExit=yes
+ExecStart=/usr/bin/env phosphor-ipmi-config-set-device-id.sh
+
+[Install]
+RequiredBy=phosphor-ipmi-host.service