1SUMMARY = "OpenBMC hwmon poller"
2DESCRIPTION = "OpenBMC hwmon poller."
3LICENSE = "Apache-2.0"
4LIC_FILES_CHKSUM = "file://LICENSE;md5=fa818a259cbed7ce8bc2a22d35a464fc"
5DEPENDS += " \
6        sdbusplus \
7        sdeventplus \
8        stdplus \
9        phosphor-dbus-interfaces \
10        phosphor-logging \
11        gpioplus \
12        cli11 \
13        "
14SRCREV = "ae7ae5b16ff7fe317744fefb5f57b8974553d71c"
15PACKAGECONFIG ??= ""
16# Meson configure option to enable/disable max31785-msl
17PACKAGECONFIG[max31785-msl] = "-Denable-max31785-msl=true, -Denable-max31785-msl=false"
18PV = "1.0+git${SRCPV}"
19PR = "r1"
20
21SRC_URI = "git://github.com/openbmc/phosphor-hwmon;branch=master;protocol=https"
22
23SYSTEMD_PACKAGES = "${PN} max31785-msl"
24SYSTEMD_SERVICE:${PN} = "xyz.openbmc_project.Hwmon@.service"
25SYSTEMD_SERVICE:max31785-msl = "${@bb.utils.contains('PACKAGECONFIG', 'max31785-msl', 'phosphor-max31785-msl@.service', '', d)}"
26S = "${WORKDIR}/git"
27
28inherit pkgconfig meson
29inherit obmc-phosphor-systemd
30
31EXTRA_OEMESON:append = " -Dtests=disabled"
32
33RDEPENDS:${PN} += "\
34        bash \
35        "
36RDEPENDS:max31785-msl = "${VIRTUAL-RUNTIME_base-utils} i2c-tools bash"
37
38RRECOMMENDS:${PN} += "${VIRTUAL-RUNTIME_phosphor-hwmon-config}"
39
40FILES:${PN} += "${base_libdir}/systemd/system/xyz.openbmc_project.Hwmon@.service"
41FILES:max31785-msl = "\
42        ${base_libdir}/systemd/system/phosphor-max31785-msl@.service \
43        ${bindir}/max31785-msl \
44        "
45
46# The following postinstall script iterate over hwmon env files:
47# 1. It adds HW_SENSOR_ID value if not set. The value being calculated
48#    as sha256sum.
49# 2. For each hwmon the script generates busconfig ACLs.
50pkg_postinst:${PN}() {
51    hwmon_dir="$D/etc/default/obmc/hwmon"
52    dbus_dir="$D/${datadir}/dbus-1/system.d"
53    if [ -n "$D" -a -d "${hwmon_dir}" ]; then
54        # Remove existing links and replace with actual copy of the file to prevent
55        # HW_SENSOR_ID variable override for different sensors' instances.
56        find "${hwmon_dir}" -type l -name \*.conf | while read f; do
57            path="$(readlink -f $f)"
58            rm -f "${f}"
59            cp "${path}" "${f}"
60        done
61        find "${hwmon_dir}" -type f -name \*.conf | while read f; do
62            path="/${f##${hwmon_dir}/}"
63            path="${path%.conf}"
64            sensor_id="$(printf "%s" "${path}" | sha256sum | cut -d\  -f1)"
65            acl_file="${dbus_dir}/xyz.openbmc_project.Hwmon-${sensor_id}.conf"
66            egrep -q '^HW_SENSOR_ID\s*=' "${f}" ||
67                printf "\n# Sensor id for %s\nHW_SENSOR_ID = \"%s\"\n" "${path}" "${sensor_id}" >> "${f}"
68            # Extract HW_SENSOR_ID that could be either quoted or unquoted string.
69            sensor_id="$(sed -n 's,^HW_SENSOR_ID\s*=\s*"\?\(.[^" ]\+\)\s*"\?,\1,p' "${f}")"
70            [ ! -f "${acl_file}" ] || continue
71            path_s="$(echo "${path}" | sed 's,\-\-,\\-\\-,g')"
72            cat <<EOF>"${acl_file}"
73<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
74 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
75<busconfig>
76  <policy user="root">
77    <!-- ${path_s} -->
78    <allow own="xyz.openbmc_project.Hwmon-${sensor_id}.Hwmon1"/>
79    <allow send_destination="xyz.openbmc_project.Hwmon-${sensor_id}.Hwmon1"/>
80  </policy>
81</busconfig>
82EOF
83        done
84    fi
85}
86
87PACKAGE_BEFORE_PN = "max31785-msl"
88