PHAL: Add service dependency to DEVTREE creation

Start the services that require DEVTREE after the
openpower-update-bios-attr-table.service since that's the one that
sets up the DEVTREE symlink. Also update the path to DEVTREE to the one
defined by the meson options.

Tested: Verified phal started after the bios attr service file, powered
on, and issued reboot at power on without any errors. Verified service
files had devtree path of:
Environment="PDBG_DTB=/media/hostfw/running/DEVTREE"

Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
Change-Id: If41f86b287b70c48d17c6f4b2af9aa0adfb81488
diff --git a/extensions/phal/pdbg_utils.cpp b/extensions/phal/pdbg_utils.cpp
index 8eadd3c..7dfc5cb 100644
--- a/extensions/phal/pdbg_utils.cpp
+++ b/extensions/phal/pdbg_utils.cpp
@@ -3,6 +3,8 @@
 #include <libpdbg.h>
 }
 
+#include "config.h"
+
 #include "extensions/phal/pdbg_utils.hpp"
 #include "extensions/phal/phal_error.hpp"
 
@@ -125,10 +127,7 @@
 void setDevtreeEnv()
 {
     // PDBG_DTB environment variable set to CEC device tree path
-    static constexpr auto PDBG_DTB_PATH =
-        "/var/lib/phosphor-software-manager/pnor/rw/DEVTREE";
-
-    if (setenv("PDBG_DTB", PDBG_DTB_PATH, 1))
+    if (setenv("PDBG_DTB", CEC_DEVTREE_RW_PATH, 1))
     {
         log<level::ERR>(
             fmt::format("Failed to set PDBG_DTB: ({})", strerror(errno))
diff --git a/meson.build b/meson.build
index 889109d..fddea45 100644
--- a/meson.build
+++ b/meson.build
@@ -61,6 +61,9 @@
 unit_subs = configuration_data()
 unit_subs.set('bindir', join_paths(get_option('prefix'), get_option('bindir')))
 unit_subs.set('ENABLE_PHAL_TRUE', '#')
+unit_subs.set('CEC_DEVTREE_RW_PATH', get_option('CEC_DEVTREE_RW_PATH'),
+               description : 'Path to the devtree file r/w version'
+             )
 
 if get_option('phal').enabled() and get_option('p9').enabled()
     error('phal and p9 cannot be selected at the same time')
diff --git a/service_files/op-continue-mpreboot@.service.in b/service_files/op-continue-mpreboot@.service.in
index d391104..638bb1d 100644
--- a/service_files/op-continue-mpreboot@.service.in
+++ b/service_files/op-continue-mpreboot@.service.in
@@ -7,11 +7,12 @@
 Wants=obmc-power-on@%i.target
 After=obmc-power-on@%i.target
 After=start_host@%i.service
+After=openpower-update-bios-attr-table.service
 Conflicts=obmc-host-stop@%i.target
 ConditionPathExists=/run/openbmc/mpreboot@%i
 
 [Service]
-@ENABLE_PHAL_TRUE@Environment="PDBG_DTB=/var/lib/phosphor-software-manager/pnor/rw/DEVTREE"
+@ENABLE_PHAL_TRUE@Environment="PDBG_DTB=@CEC_DEVTREE_RW_PATH@"
 ExecStart=/bin/rm -f /run/openbmc/mpreboot@%i
 ExecStart=/usr/bin/openpower-proc-control startHostMpReboot
 Type=oneshot
diff --git a/service_files/op-enter-mpreboot@.service.in b/service_files/op-enter-mpreboot@.service.in
index b639f32..06a22b8 100644
--- a/service_files/op-enter-mpreboot@.service.in
+++ b/service_files/op-enter-mpreboot@.service.in
@@ -7,10 +7,11 @@
 Before=op-stop-instructions@%i.service
 After=phosphor-reset-sensor-states@%i.service
 Before=phosphor-reboot-host@%i.service
+After=openpower-update-bios-attr-table.service
 Conflicts=obmc-host-startmin@%i.target
 
 [Service]
-@ENABLE_PHAL_TRUE@Environment="PDBG_DTB=/var/lib/phosphor-software-manager/pnor/rw/DEVTREE"
+@ENABLE_PHAL_TRUE@Environment="PDBG_DTB=@CEC_DEVTREE_RW_PATH@"
 RemainAfterExit=yes
 Type=oneshot
 ExecStart=/usr/bin/openpower-proc-control enterMpReboot
diff --git a/service_files/op-reset-host-check@.service.in b/service_files/op-reset-host-check@.service.in
index 50d1e90..abada7c 100644
--- a/service_files/op-reset-host-check@.service.in
+++ b/service_files/op-reset-host-check@.service.in
@@ -8,6 +8,7 @@
 Before=obmc-host-reset-running@%i.target
 Wants=op-reset-chassis-on@%i.service
 After=op-reset-chassis-on@%i.service
+After=openpower-update-bios-attr-table.service
 Conflicts=obmc-host-stop@%i.target
 ConditionPathExists=/run/openbmc/chassis@%i-on
 ConditionPathExists=!/run/openbmc/host@%i-on
diff --git a/service_files/op-reset-host-clear.service.in b/service_files/op-reset-host-clear.service.in
index 158bb27..ff757b7 100644
--- a/service_files/op-reset-host-clear.service.in
+++ b/service_files/op-reset-host-clear.service.in
@@ -2,6 +2,7 @@
 Description=Clear host running status register
 Wants=obmc-host-stop-pre@0.target
 Before=obmc-host-stop-pre@0.target
+After=openpower-update-bios-attr-table.service
 Conflicts=obmc-host-startmin@0.target
 
 [Service]
diff --git a/service_files/op-stop-instructions@.service.in b/service_files/op-stop-instructions@.service.in
index af5646e..2eaee19 100644
--- a/service_files/op-stop-instructions@.service.in
+++ b/service_files/op-stop-instructions@.service.in
@@ -5,6 +5,7 @@
 Wants=obmc-host-stopping@%i.target
 Before=obmc-host-stopping@%i.target
 After=op-occ-disable@%i.service
+After=openpower-update-bios-attr-table.service
 Conflicts=obmc-host-startmin@%i.target
 ConditionPathExists=/sys/class/fsi-master/fsi0/slave@00:00/cfam_id
 ConditionPathExists=!/run/openbmc/mpreboot@%i
diff --git a/service_files/phal-export-devtree@.service.in b/service_files/phal-export-devtree@.service.in
index 138c210..3fab02e 100644
--- a/service_files/phal-export-devtree@.service.in
+++ b/service_files/phal-export-devtree@.service.in
@@ -2,6 +2,7 @@
 Description=Export Host%i PHAL devtree attributes
 Wants=obmc-host-started@%i.target
 After=obmc-host-started@%i.target
+After=openpower-update-bios-attr-table.service
 Conflicts=obmc-host-stop@%i.target
 
 [Service]
diff --git a/service_files/phal-import-devtree@.service.in b/service_files/phal-import-devtree@.service.in
index 08dc4c2..53bde5a 100644
--- a/service_files/phal-import-devtree@.service.in
+++ b/service_files/phal-import-devtree@.service.in
@@ -2,6 +2,7 @@
 Description=Import Host%i PHAL devtree attributes
 After=obmc-host-reset-running@%i.target
 Before=attn_handler.service
+After=openpower-update-bios-attr-table.service
 ConditionPathExists=/run/openbmc/chassis@%i-on
 ConditionPathExists=/run/openbmc/host@%i-on
 
diff --git a/service_files/phal-reinit-devtree.service.in b/service_files/phal-reinit-devtree.service.in
index e6ba4a6..fd2a156 100644
--- a/service_files/phal-reinit-devtree.service.in
+++ b/service_files/phal-reinit-devtree.service.in
@@ -1,6 +1,7 @@
 [Unit]
 Description=Reinit POWER CEC system device tree
 Before=start_host@0.service
+After=openpower-update-bios-attr-table.service
 ConditionPathExists=!/run/openbmc/host@0-on
 
 [Service]
diff --git a/service_files/proc-pre-poweroff@.service.in b/service_files/proc-pre-poweroff@.service.in
index ee0fb25..be9c32c 100644
--- a/service_files/proc-pre-poweroff@.service.in
+++ b/service_files/proc-pre-poweroff@.service.in
@@ -6,6 +6,7 @@
 Before=obmc-power-stop-pre@%i.target
 Wants=obmc-host-stopped@%i.target
 After=obmc-host-stopped@%i.target
+After=openpower-update-bios-attr-table.service
 Conflicts=obmc-chassis-poweron@%i.target
 
 [Service]
diff --git a/service_files/xyz.openbmc_project.Control.Host.NMI.service.in b/service_files/xyz.openbmc_project.Control.Host.NMI.service.in
index e13687d..06f85d8 100644
--- a/service_files/xyz.openbmc_project.Control.Host.NMI.service.in
+++ b/service_files/xyz.openbmc_project.Control.Host.NMI.service.in
@@ -2,6 +2,7 @@
 Description=Start the Open Power Host Control NMI service
 Wants=obmc-host-started@0.target
 After=obmc-host-started@0.target
+After=openpower-update-bios-attr-table.service
 Conflicts=obmc-host-stop@0.target
 
 [Service]