1SUMMARY = "Phosphor Debug Collector"
2DESCRIPTION = "Phosphor Debug Collector provides mechanisms \
3to collect various log files and system parameters. \
4This will be helpful for troubleshooting the problems in OpenBMC \
5based systems."
6DEPENDS += " \
7        phosphor-dbus-interfaces \
8        phosphor-logging \
9        sdbusplus \
10        ${PYTHON_PN}-sdbus++-native \
11        autoconf-archive-native \
12        virtual/phosphor-debug-errors \
13        ${PYTHON_PN}-native \
14        ${PYTHON_PN}-pyyaml-native \
15        ${PYTHON_PN}-setuptools-native \
16        ${PYTHON_PN}-mako-native \
17        fmt \
18"
19PACKAGECONFIG ??= "${@bb.utils.contains_any('DISTRO_FEATURES', \
20         'obmc-ubi-fs phosphor-mmc obmc-static-norootfs', '', 'jffs-workaround', d)}"
21PACKAGECONFIG[jffs-workaround] = "-Djffs-workaround=enabled, \
22        -Djffs-workaround=disabled"
23PACKAGECONFIG[host-dump-transport-pldm] = " \
24        -Dhost-transport=pldm,, \
25        libpldm \
26        "
27PACKAGECONFIG[openpower-dumps-extension] = " \
28       -Dopenpower-dumps-extension=enabled, \
29       -Dopenpower-dumps-extension=disabled  \
30"
31PV = "1.0+git${SRCPV}"
32PR = "r1"
33
34SRC_URI += "file://coretemp.conf"
35
36SYSTEMD_PACKAGES = "${PN}-monitor"
37SYSTEMD_SUBSTITUTIONS += "BMC_DUMP_PATH:${bmc_dump_path}:${MGR_SVC}"
38SYSTEMD_SERVICE:${PN}-monitor += "obmc-dump-monitor.service"
39SYSTEMD_SERVICE:${PN}-monitor += "ramoops-monitor.service"
40S = "${WORKDIR}/git"
41
42inherit pkgconfig meson \
43        obmc-phosphor-dbus-service \
44        python3native \
45        phosphor-debug-collector
46
47EXTRA_OEMESON = " \
48    -DBMC_DUMP_PATH=${bmc_dump_path} \
49    -DERROR_MAP_YAML=${STAGING_DIR_NATIVE}/${datadir}/dump/errors_watch.yaml \
50    "
51
52do_install:append() {
53    install -d ${D}${exec_prefix}/lib/tmpfiles.d
54    install -m 644 ${WORKDIR}/coretemp.conf ${D}${exec_prefix}/lib/tmpfiles.d/
55}
56do_install[postfuncs] += "install_dreport"
57do_install[postfuncs] += "install_dreport_conf_file"
58do_install[postfuncs] += "install_dreport_plugins_scripts"
59do_install[postfuncs] += "install_dreport_include_scripts"
60do_install[postfuncs] += "install_dreport_user_scripts"
61
62RDEPENDS:${PN}-manager += " \
63        ${PN}-dreport \
64"
65RDEPENDS:${PN}-dreport += " \
66        systemd \
67        ${VIRTUAL-RUNTIME_base-utils} \
68        bash \
69        xz \
70"
71RDEPENDS:${PN}-scripts += " \
72        bash \
73"
74
75FILES:${PN}-manager += " \
76    ${bindir}/phosphor-dump-manager \
77    ${bindir}/phosphor-offload-handler \
78    ${exec_prefix}/lib/tmpfiles.d/coretemp.conf \
79    ${datadir}/dump/ \
80    "
81FILES:${PN}-monitor += "${bindir}/phosphor-dump-monitor"
82FILES:${PN}-monitor += "${bindir}/phosphor-ramoops-monitor"
83FILES:${PN}-dreport += "${bindir}/dreport"
84FILES:${PN}-scripts += "${dreport_dir}"
85
86require phosphor-debug-collector.inc
87
88ALLOW_EMPTY:${PN} = "1"
89
90DEBUG_COLLECTOR_PKGS = " \
91    ${PN}-manager \
92    ${PN}-monitor \
93    ${PN}-dreport \
94    ${PN}-scripts \
95"
96PACKAGE_BEFORE_PN += "${DEBUG_COLLECTOR_PKGS}"
97DBUS_PACKAGES = "${PN}-manager"
98MGR_SVC ?= "xyz.openbmc_project.Dump.Manager.service"
99DBUS_SERVICE:${PN}-manager += "${MGR_SVC}"
100# Install dreport script
101# From tools/dreport.d/dreport to /usr/bin/dreport
102install_dreport() {
103    install -d ${D}${bindir}
104    install -m 0755 ${S}/tools/dreport.d/dreport \
105                    ${D}${bindir}/dreport
106}
107# Install dreport sample configuration file
108# From tools/dreport.d/sample.conf
109# to /usr/share/dreport.d/conf.d/dreport.conf
110install_dreport_conf_file() {
111    install -d ${D}${dreport_conf_dir}
112    install -m 0644 ${S}/tools/dreport.d/sample.conf \
113                        ${D}${dreport_conf_dir}/dreport.conf
114}
115# Install dreport plugins
116# From tools/dreport.d/plugins.d to /usr/share/dreport.d/plugins.d
117install_dreport_plugins_scripts() {
118    install -d ${D}${dreport_plugin_dir}
119    install -m 0755 ${S}/tools/dreport.d/plugins.d/* ${D}${dreport_plugin_dir}/
120}
121# Install dreport utility functions
122# From tools/dreport.d/include.d to /usr/share/dreport.d/include.d
123install_dreport_include_scripts() {
124    install -d ${D}${dreport_include_dir}
125    install -m 0755 ${S}/tools/dreport.d/include.d/* \
126                ${D}${dreport_include_dir}/
127}
128# Make the links for a single user plugin script
129# Create user directories based on the dump type value in the config section
130# Create softlinks for the base scripts in the user directories
131def install_dreport_user_script(script_path, d):
132    import re
133    import configparser
134    #Read the user types from the dreport.conf file
135    configure = configparser.ConfigParser()
136    conf_dir  = d.getVar('D', True) + d.getVar('dreport_conf_dir', True)
137    confsource = os.path.join(conf_dir, "dreport.conf")
138    configure.read(confsource)
139    config = ("config:")
140    section = "DumpType"
141    dreport_dir = d.getVar('D', True) + d.getVar('dreport_dir', True)
142    script = os.path.basename(script_path)
143    srclink = os.path.join(d.getVar('dreport_plugin_dir', True), script)
144    file = open(script_path, "r")
145    for line in file:
146        if not config in line:
147            continue
148        revalue = re.search('[0-9]+.[0-9]+', line)
149        if not revalue:
150            bb.warn("Invalid format for config value =%s" % line)
151            continue
152        parse_value = revalue.group(0)
153        config_values = re.split(r'\W+', parse_value, 1)
154        if(len(config_values) != 2):
155            bb.warn("Invalid config value=%s" % parse_value)
156            break;
157        priority = config_values[1]
158        types = [int(d) for d in str(config_values[0])]
159        for type in types:
160            if not configure.has_option(section, str(type)):
161                bb.warn("Invalid dump type id =%s" % (str(type)))
162                continue
163            typestr = configure.get(section, str(type))
164            destdir = os.path.join(dreport_dir, ("pl_" + typestr + ".d"))
165            if not os.path.exists(destdir):
166                os.makedirs(destdir)
167            linkname = "E" + priority + script
168            destlink = os.path.join(destdir, linkname)
169            os.symlink(srclink, destlink)
170    file.close()
171#Make the links for all the plugins
172python install_dreport_user_scripts() {
173    source = d.getVar('S', True)
174    source_path = os.path.join(source, "tools", "dreport.d", "plugins.d")
175    scripts = os.listdir(source_path)
176    for script in scripts:
177        srcname = os.path.join(source_path, script)
178        install_dreport_user_script(srcname, d)
179}
180