oem_ibm: Move the NVRAM files to the hostfw directory

This commit would :
- Move the NVRAM files from /var/ on the BMC to the hostfw directory so
  that they don't get erased during a BMC factory reset.

- To help migrate existing systems, check if the files exist in /var/,
  and if they do, move them to the hostfw destination.

- This also adds dependent services that ensure that the links being
  setup correctly in var/lib/phosphor-software-manager/hostfw/ is run
  first.

- The services to clear PHYP NVRAM are not needed anymore. Instead of
  the BMC clearing them, the hypervisor will now clear them if the
  pvm_clear_nvram bios attribute is set.

Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: If8da88347a82d212b30c3cb6354037b62887c67c
diff --git a/oem/ibm/service_files/meson.build b/oem/ibm/service_files/meson.build
index fdc7b01..96c3b07 100644
--- a/oem/ibm/service_files/meson.build
+++ b/oem/ibm/service_files/meson.build
@@ -1,3 +1,5 @@
+subdir('scripts')
+
 configure_file(
   copy: true,
   input: 'pldm-create-phyp-nvram.service',
@@ -12,18 +14,3 @@
   install_dir: systemd_system_unit_dir,
   output: 'pldm-create-phyp-nvram-cksum.service',
 )
-configure_file(
-  copy: true,
-  input: 'pldm-reset-phyp-nvram.service',
-  install: true,
-  install_dir: systemd_system_unit_dir,
-  output: 'pldm-reset-phyp-nvram.service',
-)
-configure_file(
-  copy: true,
-  input: 'pldm-reset-phyp-nvram-cksum.service',
-  install: true,
-  install_dir: systemd_system_unit_dir,
-  output: 'pldm-reset-phyp-nvram-cksum.service',
-)
-
diff --git a/oem/ibm/service_files/pldm-create-phyp-nvram-cksum.service b/oem/ibm/service_files/pldm-create-phyp-nvram-cksum.service
index 9e0100d..d59086d 100644
--- a/oem/ibm/service_files/pldm-create-phyp-nvram-cksum.service
+++ b/oem/ibm/service_files/pldm-create-phyp-nvram-cksum.service
@@ -1,10 +1,13 @@
 [Unit]
 Description=Create empty PHYP-NVRAM-CKSUM file
-ConditionPathExists=!/var/lib/pldm/PHYP-NVRAM-CKSUM
+Wants=obmc-vpnor-updatesymlinks.service
+After=obmc-vpnor-updatesymlinks.service
+Wants=obmc-flash-bios-init.service
+After=obmc-flash-bios-init.service
+ConditionPathExists=!/var/lib/phosphor-software-manager/hostfw/nvram/PHYP-NVRAM-CKSUM
 
 [Service]
-ExecStart=/bin/mkdir -p /var/lib/pldm/
-ExecStart=/bin/dd if=/dev/zero of=/var/lib/pldm/PHYP-NVRAM-CKSUM bs=16 count=1
+ExecStart=/usr/bin/create-NVRAM-cksum-file
 Type=oneshot
 RemainAfterExit=no
 
diff --git a/oem/ibm/service_files/pldm-create-phyp-nvram.service b/oem/ibm/service_files/pldm-create-phyp-nvram.service
index 0866579..edf79d9 100644
--- a/oem/ibm/service_files/pldm-create-phyp-nvram.service
+++ b/oem/ibm/service_files/pldm-create-phyp-nvram.service
@@ -1,10 +1,13 @@
 [Unit]
 Description=Create empty PHYP-NVRAM file
-ConditionPathExists=!/var/lib/pldm/PHYP-NVRAM
+Wants=obmc-vpnor-updatesymlinks.service
+After=obmc-vpnor-updatesymlinks.service
+Wants=obmc-flash-bios-init.service
+After=obmc-flash-bios-init.service
+ConditionPathExists=!/var/lib/phosphor-software-manager/hostfw/nvram/PHYP-NVRAM
 
 [Service]
-ExecStart=/bin/mkdir -p /var/lib/pldm/
-ExecStart=/bin/dd if=/dev/zero of=/var/lib/pldm/PHYP-NVRAM bs=1024 count=145408
+ExecStart=/usr/bin/create-NVRAM-file
 Type=oneshot
 RemainAfterExit=no
 
diff --git a/oem/ibm/service_files/pldm-reset-phyp-nvram-cksum.service b/oem/ibm/service_files/pldm-reset-phyp-nvram-cksum.service
deleted file mode 100644
index 5b8d2fd..0000000
--- a/oem/ibm/service_files/pldm-reset-phyp-nvram-cksum.service
+++ /dev/null
@@ -1,9 +0,0 @@
-[Unit]
-Description=Reset PHYP-NVRAM-CKSUM file
-Requires=pldm-create-phyp-nvram-cksum.service
-Before=pldm-create-phyp-nvram-cksum.service
-
-[Service]
-ExecStart=/bin/rm -f /var/lib/pldm/PHYP-NVRAM-CKSUM
-Type=oneshot
-RemainAfterExit=no
diff --git a/oem/ibm/service_files/pldm-reset-phyp-nvram.service b/oem/ibm/service_files/pldm-reset-phyp-nvram.service
deleted file mode 100644
index 12827b5..0000000
--- a/oem/ibm/service_files/pldm-reset-phyp-nvram.service
+++ /dev/null
@@ -1,9 +0,0 @@
-[Unit]
-Description=Reset PHYP-NVRAM file
-Requires=pldm-create-phyp-nvram.service
-Before=pldm-create-phyp-nvram.service
-
-[Service]
-ExecStart=/bin/rm -f /var/lib/pldm/PHYP-NVRAM
-Type=oneshot
-RemainAfterExit=no
diff --git a/oem/ibm/service_files/scripts/create-NVRAM-cksum-file b/oem/ibm/service_files/scripts/create-NVRAM-cksum-file
new file mode 100755
index 0000000..276f824
--- /dev/null
+++ b/oem/ibm/service_files/scripts/create-NVRAM-cksum-file
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ -f /var/lib/pldm/PHYP-NVRAM-CKSUM ]; then
+    mv /var/lib/pldm/PHYP-NVRAM-CKSUM /var/lib/phosphor-software-manager/hostfw/nvram/PHYP-NVRAM-CKSUM;
+else
+    dd if=/dev/zero of=/var/lib/phosphor-software-manager/hostfw/nvram/PHYP-NVRAM-CKSUM bs=16 count=1;
+fi
diff --git a/oem/ibm/service_files/scripts/create-NVRAM-file b/oem/ibm/service_files/scripts/create-NVRAM-file
new file mode 100755
index 0000000..6e35c46
--- /dev/null
+++ b/oem/ibm/service_files/scripts/create-NVRAM-file
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ -f /var/lib/pldm/PHYP-NVRAM ]; then
+    mv /var/lib/pldm/PHYP-NVRAM /var/lib/phosphor-software-manager/hostfw/nvram/PHYP-NVRAM;
+else
+    dd if=/dev/zero of=/var/lib/phosphor-software-manager/hostfw/nvram/PHYP-NVRAM bs=1024 count=145408;
+fi
diff --git a/oem/ibm/service_files/scripts/meson.build b/oem/ibm/service_files/scripts/meson.build
new file mode 100644
index 0000000..35b2626
--- /dev/null
+++ b/oem/ibm/service_files/scripts/meson.build
@@ -0,0 +1,5 @@
+install_data([
+    'create-NVRAM-file',
+    'create-NVRAM-cksum-file'],
+    install_dir: get_option('bindir')
+)