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 autotools \
24        pkgconfig \
25        obmc-phosphor-dbus-service \
26        pythonnative \
27        phosphor-debug-collector
28
29require phosphor-debug-collector.inc
30
31DEPENDS += " \
32        phosphor-dbus-interfaces \
33        phosphor-dbus-interfaces-native \
34        phosphor-logging \
35        sdbusplus \
36        sdbusplus-native \
37        autoconf-archive-native \
38        virtual/phosphor-debug-errors \
39"
40
41RDEPENDS_${PN}-manager += " \
42        ${PN}-dreport \
43"
44RDEPENDS_${PN}-dreport += " \
45        systemd \
46        ${VIRTUAL-RUNTIME_base-utils} \
47        bash \
48        xz \
49"
50RDEPENDS_${PN}-scripts += " \
51        bash \
52"
53
54MGR_SVC ?= "xyz.openbmc_project.Dump.Manager.service"
55
56SYSTEMD_SUBSTITUTIONS += "BMC_DUMP_PATH:${bmc_dump_path}:${MGR_SVC}"
57
58FILES_${PN}-manager +=  " \
59    ${sbindir}/phosphor-dump-manager \
60    ${exec_prefix}/lib/tmpfiles.d/coretemp.conf \
61    ${datadir}/dump/ \
62    "
63FILES_${PN}-monitor += "${sbindir}/phosphor-dump-monitor"
64FILES_${PN}-dreport += "${bindir}/dreport"
65FILES_${PN}-scripts += "${dreport_dir}"
66
67DBUS_SERVICE_${PN}-manager += "${MGR_SVC}"
68SYSTEMD_SERVICE_${PN}-monitor += "obmc-dump-monitor.service"
69
70EXTRA_OECONF = " \
71    BMC_DUMP_PATH=${bmc_dump_path} \
72    ERROR_MAP_YAML=${STAGING_DIR_NATIVE}/${datadir}/dump/errors_watch.yaml \
73    "
74
75S = "${WORKDIR}/git"
76SRC_URI += "file://coretemp.conf"
77
78do_install_append() {
79    install -d ${D}${exec_prefix}/lib/tmpfiles.d
80    install -m 644 ${WORKDIR}/coretemp.conf ${D}${exec_prefix}/lib/tmpfiles.d/
81}
82
83# Install dreport script
84# From tools/dreport.d/dreport to /usr/bin/dreport
85install_dreport() {
86    install -d ${D}${bindir}
87    install -m 0755 ${S}/tools/dreport.d/dreport \
88                    ${D}${bindir}/dreport
89}
90
91# Install dreport sample configuration file
92# From tools/dreport.d/sample.conf
93# to /usr/share/dreport.d/conf.d/dreport.conf
94install_dreport_conf_file() {
95    install -d ${D}${dreport_conf_dir}
96    install -m 0644 ${S}/tools/dreport.d/sample.conf \
97                        ${D}${dreport_conf_dir}/dreport.conf
98}
99
100# Install dreport plugins
101# From tools/dreport.d/plugins.d to /usr/share/dreport.d/plugins.d
102install_dreport_plugins_scripts() {
103    install -d ${D}${dreport_plugin_dir}
104    install -m 0755 ${S}/tools/dreport.d/plugins.d/* ${D}${dreport_plugin_dir}/
105}
106
107# Install dreport utility functions
108# From tools/dreport.d/include.d to /usr/share/dreport.d/include.d
109install_dreport_include_scripts() {
110    install -d ${D}${dreport_include_dir}
111    install -m 0755 ${S}/tools/dreport.d/include.d/* \
112                ${D}${dreport_include_dir}/
113}
114
115# Make the links for a single user plugin script
116# Create user directories based on the dump type value in the config section
117# Create softlinks for the base scripts in the user directories
118def install_dreport_user_script(script_path, d):
119    import re
120    import configparser
121
122    #Read the user types from the dreport.conf file
123    configure = configparser.ConfigParser()
124    conf_dir  = d.getVar('D', True) + d.getVar('dreport_conf_dir', True)
125    confsource = os.path.join(conf_dir, "dreport.conf")
126    configure.read(confsource)
127
128    config = ("config:")
129    section = "DumpType"
130    dreport_dir = d.getVar('D', True) + d.getVar('dreport_dir', True)
131
132    script = os.path.basename(script_path)
133    srclink = os.path.join(d.getVar('dreport_plugin_dir', True), script)
134
135    file = open(script_path, "r")
136
137    for line in file:
138        if not config in line:
139            continue
140        revalue = re.search('[0-9]+.[0-9]+', line)
141        if not revalue:
142            bb.warn("Invalid format for config value =%s" % line)
143            continue
144        parse_value = revalue.group(0)
145        config_values = re.split('\W+', parse_value, 1)
146        if(len(config_values) != 2):
147            bb.warn("Invalid config value=%s" % parse_value)
148            break;
149        priority = config_values[1]
150        types = [int(d) for d in str(config_values[0])]
151        for type in types:
152            if not configure.has_option(section, str(type)):
153                bb.warn("Invalid dump type id =%s" % (str(type)))
154                continue
155            typestr = configure.get(section, str(type))
156            destdir = os.path.join(dreport_dir, ("pl_" + typestr + ".d"))
157            if not os.path.exists(destdir):
158                os.makedirs(destdir)
159            linkname = "E" + priority + script
160            destlink = os.path.join(destdir, linkname)
161            os.symlink(srclink, destlink)
162
163#Make the links for all the plugins
164python install_dreport_user_scripts() {
165
166    source = d.getVar('S', True)
167    source_path = os.path.join(source, "tools", "dreport.d", "plugins.d")
168    scripts = os.listdir(source_path)
169
170    for script in scripts:
171        srcname = os.path.join(source_path, script)
172        install_dreport_user_script(srcname, d)
173}
174
175#Enable ubifs-workaround by DISTRO_FEATURE obmc-ubi-fs.
176PACKAGECONFIG_append_df-obmc-ubi-fs = " ubifs-workaround"
177PACKAGECONFIG[ubifs-workaround] = " \
178       --enable-ubifs-workaround, \
179       --disable-ubifs-workaround \
180"
181
182do_install[postfuncs] += "install_dreport"
183do_install[postfuncs] += "install_dreport_conf_file"
184do_install[postfuncs] += "install_dreport_plugins_scripts"
185do_install[postfuncs] += "install_dreport_include_scripts"
186do_install[postfuncs] += "install_dreport_user_scripts"
187