Provide the phosphor-fan-presence config YAML

On MRW based systems, this YAML will be generated from the
MRW XML, otherwise the example YAML provided by the
phosphor-fan-presence repository will be used in the build.

Change-Id: I1bf914a7e26067f62f2b2bf8b7ba1ba43591c5dc
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/meta-phosphor/classes/phosphor-fan-presence.bbclass b/meta-phosphor/classes/phosphor-fan-presence.bbclass
new file mode 100644
index 0000000..b59f1f5
--- /dev/null
+++ b/meta-phosphor/classes/phosphor-fan-presence.bbclass
@@ -0,0 +1 @@
+presence_datadir="${datadir}/phosphor-fan-presence"
diff --git a/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence-example-native.bb b/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence-example-native.bb
new file mode 100644
index 0000000..c97865e
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence-example-native.bb
@@ -0,0 +1,17 @@
+SUMMARY = "Phosphor Fan Presence Detection example data"
+PR = "r1"
+
+require phosphor-fan-presence.inc
+
+inherit native
+inherit obmc-phosphor-license
+inherit phosphor-fan-presence
+
+PROVIDES += "virtual/phosphor-fan-presence-config"
+
+S = "${WORKDIR}/git"
+
+do_install() {
+    DEST=${D}${presence_datadir}
+    install -D ${S}/example/fan-detect.yaml ${DEST}/config.yaml
+}
diff --git a/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence-mrw-native.bb b/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence-mrw-native.bb
new file mode 100644
index 0000000..267fc92
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence-mrw-native.bb
@@ -0,0 +1,25 @@
+SUMMARY = "Generate fan presence YAML from the MRW"
+PR = "r1"
+
+inherit native
+inherit obmc-phosphor-license
+inherit phosphor-fan-presence
+
+DEPENDS += " \
+           mrw-native \
+           mrw-perl-tools-native \
+           "
+
+PROVIDES += "virtual/phosphor-fan-presence-config"
+
+S = "${WORKDIR}"
+
+do_install() {
+        DEST=${D}${presence_datadir}
+        install -d ${DEST}
+
+        ${bindir}/perl-native/perl \
+            ${bindir}/gen_presence_yaml.pl \
+            -i ${datadir}/obmc-mrw/${MACHINE}.xml \
+            -o ${DEST}/config.yaml
+}
diff --git a/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence.bb b/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence.bb
index ec17267..2d5b5b8 100644
--- a/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence.bb
+++ b/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence.bb
@@ -2,18 +2,20 @@
 DESCRIPTION = "Phosphor fan presence provides a set of fan presence \
 daemons to monitor fan presence changes by different methods of \
 presence detection."
-HOMEPAGE = "https://github.com/openbmc/phosphor-fan-presence"
 PR = "r1"
-LICENSE = "Apache-2.0"
-LIC_FILES_CHKSUM = "file://${S}/LICENSE;md5=e3fc50a88d0a364313df4b21ef20c29e"
+
+require ${PN}.inc
 
 inherit autotools pkgconfig pythonnative
 inherit obmc-phosphor-systemd
+inherit phosphor-fan-presence
 
 DEPENDS += "autoconf-archive-native"
 DEPENDS += "python-pyyaml-native"
+DEPENDS += "python-mako-native"
 DEPENDS += "sdbusplus"
 DEPENDS += "phosphor-logging"
+DEPENDS += "virtual/phosphor-fan-presence-config"
 RDEPENDS_${PN} += "sdbusplus"
 
 FAN_PRESENCE_PACKAGES = " \
@@ -34,7 +36,7 @@
 SYSTEMD_SERVICE_${PN}-tach += "${TMPL}"
 SYSTEMD_LINK_${PN} += "${@compose_list(d, 'FMT', 'OBMC_CHASSIS_INSTANCES')}"
 
-SRC_URI += "git://github.com/openbmc/phosphor-fan-presence"
-SRCREV = "2b44a6c0b282cf50c563a175535c4c32f55a81dc"
-
 S = "${WORKDIR}/git"
+
+EXTRA_OECONF = \
+    "FAN_DETECT_YAML_FILE=${STAGING_DIR_NATIVE}${presence_datadir}/config.yaml"
diff --git a/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence.inc b/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence.inc
new file mode 100644
index 0000000..e251c83
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/fans/phosphor-fan-presence.inc
@@ -0,0 +1,5 @@
+HOMEPAGE = "https://github.com/openbmc/phosphor-fan-presence"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${S}/LICENSE;md5=e3fc50a88d0a364313df4b21ef20c29e"
+SRC_URI += "git://github.com/openbmc/phosphor-fan-presence"
+SRCREV = "2b44a6c0b282cf50c563a175535c4c32f55a81dc"
diff --git a/meta-phosphor/conf/distro/include/phosphor-defaults.inc b/meta-phosphor/conf/distro/include/phosphor-defaults.inc
index f78ea33..06995ba 100644
--- a/meta-phosphor/conf/distro/include/phosphor-defaults.inc
+++ b/meta-phosphor/conf/distro/include/phosphor-defaults.inc
@@ -126,5 +126,13 @@
 PREFERRED_PROVIDER_virtual/phosphor-logging-callouts ?= \
     "${@cf_enabled(d, 'obmc-mrw', 'phosphor-logging-callouts-mrw-native', 'phosphor-logging-callouts-example-native')}"
 
+# The phosphor-fan-presence application is data driven and requires an
+# input YAML that maps fans to their tach sensors.
+# This virtual is a native recipe that provides that mapping by installing
+# configuration files in the format and native sysroot location expected by
+# the phosphor-fan-presence build process in the native sysroot.
+PREFERRED_PROVIDER_virtual/phosphor-fan-presence-config ?= \
+    "${@cf_enabled(d, 'obmc-mrw', 'phosphor-fan-presence-mrw-native', 'phosphor-fan-presence-example-native')}"
+
 OBMC_DBUS_PATH_ROOT ?= "/xyz/openbmc_project"
 OBMC_DBUS_IFACE_ROOT ?= "xyz.openbmc_project"