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