Move UBI service files into repo

Move the service files for the UBI layout from the openbmc/openbmc
repo to the local one.

Tested: The service files are installed in /lib/systemd/system/ and
        code update on Witherspoon is successful.

Change-Id: I988045886fadbd2216ca91aba952a40ca1228e33
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/configure.ac b/configure.ac
index 8e31832..2da97ad 100755
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,27 @@
 # Checks for library functions
 LT_INIT # Required for systemd linking
 
+PKG_PROG_PKG_CONFIG
+AC_ARG_WITH([systemdsystemunitdir],
+     [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],
+     [],
+     [with_systemdsystemunitdir=auto]
+)
+AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"],
+    [def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
+     AS_IF([test "x$def_systemdsystemunitdir" = "x"],
+           [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
+                  [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])]
+            )
+            with_systemdsystemunitdir=no],
+           [with_systemdsystemunitdir="$def_systemdsystemunitdir"]
+     )]
+)
+AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
+      [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])]
+)
+AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])
+
 # Check/set gtest specific functions.
 AX_PTHREAD([GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"],[GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=0"])
 AC_SUBST(GTEST_CPPFLAGS)
diff --git a/ubi/Makefile.am.include b/ubi/Makefile.am.include
index 1a5128a..b343a74 100644
--- a/ubi/Makefile.am.include
+++ b/ubi/Makefile.am.include
@@ -1,3 +1,18 @@
 phosphor_image_updater_SOURCES += \
 	%reldir%/flash.cpp \
 	%reldir%/item_updater_helper.cpp
+
+if HAVE_SYSTEMD
+systemdsystemunit_DATA = \
+	%reldir%/obmc-flash-bmc-cleanup.service \
+	%reldir%/obmc-flash-bmc-mirroruboot.service \
+	%reldir%/obmc-flash-bmc-ubiremount.service \
+	%reldir%/obmc-flash-bmc-ubiro@.service \
+	%reldir%/obmc-flash-bmc-ubiro-remove@.service \
+	%reldir%/obmc-flash-bmc-ubirw.service \
+	%reldir%/obmc-flash-bmc-ubirw-remove.service \
+	%reldir%/obmc-flash-bmc-updateubootvars@.service \
+	%reldir%/reboot-guard-disable.service \
+	%reldir%/reboot-guard-enable.service \
+	%reldir%/usr-local.mount
+endif
diff --git a/ubi/obmc-flash-bmc-cleanup.service b/ubi/obmc-flash-bmc-cleanup.service
new file mode 100644
index 0000000..6742d95
--- /dev/null
+++ b/ubi/obmc-flash-bmc-cleanup.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Clean up UBI volumes unattached to a BMC version after DeleteAll
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStartPre=/usr/bin/obmc-flash-bmc createenvbackup
+ExecStart=/usr/bin/obmc-flash-bmc ubicleanup
diff --git a/ubi/obmc-flash-bmc-mirroruboot.service b/ubi/obmc-flash-bmc-mirroruboot.service
new file mode 100644
index 0000000..8f0a58e
--- /dev/null
+++ b/ubi/obmc-flash-bmc-mirroruboot.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Copy uboot from the currently booted bmc chip to the alternate chip
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/usr/bin/obmc-flash-bmc mirroruboot
diff --git a/ubi/obmc-flash-bmc-ubiremount.service b/ubi/obmc-flash-bmc-ubiremount.service
new file mode 100644
index 0000000..52ac12b
--- /dev/null
+++ b/ubi/obmc-flash-bmc-ubiremount.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Remount the ubi volume after a reboot
+Wants=xyz.openbmc_project.Software.BMC.Updater.service
+Before=xyz.openbmc_project.Software.BMC.Updater.service
+Wants=obmc-flash-bmc-setenv@rwreset.service
+After=obmc-flash-bmc-setenv@rwreset.service
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/usr/bin/obmc-flash-bmc ubiremount
+
+[Install]
+WantedBy=multi-user.target
diff --git a/ubi/obmc-flash-bmc-ubiro-remove@.service b/ubi/obmc-flash-bmc-ubiro-remove@.service
new file mode 100644
index 0000000..e434bec
--- /dev/null
+++ b/ubi/obmc-flash-bmc-ubiro-remove@.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Deletes read-only and kernel ubi volume %I
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/usr/bin/obmc-flash-bmc ubiremove rofs-%i
+ExecStart=/usr/bin/obmc-flash-bmc ubiremove kernel-%i
diff --git a/ubi/obmc-flash-bmc-ubiro@.service b/ubi/obmc-flash-bmc-ubiro@.service
new file mode 100644
index 0000000..44d152f
--- /dev/null
+++ b/ubi/obmc-flash-bmc-ubiro@.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Store read-only images %I to BMC storage
+OnFailure=obmc-flash-bmc-ubiro-remove@%i.service
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStartPre=/usr/bin/obmc-flash-bmc createenvbackup
+ExecStart=/usr/bin/obmc-flash-bmc ubiro {RO_MTD} rofs-%i %i
+ExecStart=/usr/bin/obmc-flash-bmc ubikernel {KERNEL_MTD} kernel-%i %i
+ExecStart=/usr/bin/obmc-flash-bmc mtduboot u-boot %i
diff --git a/ubi/obmc-flash-bmc-ubirw-remove.service b/ubi/obmc-flash-bmc-ubirw-remove.service
new file mode 100644
index 0000000..aa8e400
--- /dev/null
+++ b/ubi/obmc-flash-bmc-ubirw-remove.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Deletes BMC read-write ubi volume
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/usr/bin/obmc-flash-bmc ubiremove rwfs
diff --git a/ubi/obmc-flash-bmc-ubirw.service b/ubi/obmc-flash-bmc-ubirw.service
new file mode 100644
index 0000000..93679b0
--- /dev/null
+++ b/ubi/obmc-flash-bmc-ubirw.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Create BMC read-write ubi volume
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/usr/bin/obmc-flash-bmc ubirw {RW_MTD} rwfs {RW_SIZE}
diff --git a/ubi/obmc-flash-bmc-updateubootvars@.service b/ubi/obmc-flash-bmc-updateubootvars@.service
new file mode 100644
index 0000000..a041bfe
--- /dev/null
+++ b/ubi/obmc-flash-bmc-updateubootvars@.service
@@ -0,0 +1,7 @@
+[Unit]
+Description= Updates the u-boot variable to point BMC version to %I
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/usr/bin/obmc-flash-bmc updateubootvars %i
diff --git a/ubi/reboot-guard-disable.service b/ubi/reboot-guard-disable.service
new file mode 100644
index 0000000..70d702f
--- /dev/null
+++ b/ubi/reboot-guard-disable.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Removes the guard that blocks BMC reboot
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/usr/bin/obmc-flash-bmc rebootguarddisable
diff --git a/ubi/reboot-guard-enable.service b/ubi/reboot-guard-enable.service
new file mode 100644
index 0000000..7bd2873
--- /dev/null
+++ b/ubi/reboot-guard-enable.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Enable a guard that blocks BMC reboot
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/usr/bin/obmc-flash-bmc rebootguardenable
diff --git a/ubi/usr-local.mount b/ubi/usr-local.mount
new file mode 100644
index 0000000..7aa2cf6
--- /dev/null
+++ b/ubi/usr-local.mount
@@ -0,0 +1,7 @@
+[Unit]
+Description=/usr/local
+
+[Mount]
+What=tmpfs
+Where=/usr/local
+Type=tmpfs