Set BMC boot complete checkpoint in unprovision mode

In non provisional mode, pfr service won't run because in pfr manager
code we are calling exit call to stop pfr service.
Code modified when we recieved FinishTimestamp signal from systemd and
then checking provisional status if pfr is unprovisioned then calling
exit call to stop pfr service.

Modified variable name  from  finishedSettingChkPoint to bmcBootCompleteChkPointDone
Modified function name setBMCBootCheckpoint to setBMCBootCompleteChkPoint

Tested:
During unprovision and provision mode BMC checkpoint is setting to 0x09

Change-Id: I91c1fc1d91a44b32ab94924f76b80c0a393ddde1
Signed-off-by: sri anjaneyulu alapati <srix.anjaneyulu.alapati@intel.com>
diff --git a/libpfr/inc/pfr.hpp b/libpfr/inc/pfr.hpp
index 4110f45..5b2c44d 100644
--- a/libpfr/inc/pfr.hpp
+++ b/libpfr/inc/pfr.hpp
@@ -54,7 +54,7 @@
 int getPlatformState(uint8_t& state);
 int readCpldReg(const ActionType& action, uint8_t& value);
 std::string readCPLDVersion();
-int setBMCBootCheckpoint(const uint8_t checkPoint);
+int setBMCBootCompleteChkPoint(const uint8_t checkPoint);
 void init(std::shared_ptr<sdbusplus::asio::connection> conn,
           bool& i2cConfigLoaded);
 int setBMCBusy(bool setValue);
diff --git a/libpfr/src/pfr.cpp b/libpfr/src/pfr.cpp
index 61c52f0..0997d76 100644
--- a/libpfr/src/pfr.cpp
+++ b/libpfr/src/pfr.cpp
@@ -82,6 +82,8 @@
     "MAIN_PLD_MINOR_REV_BIT1", "MAIN_PLD_MINOR_REV_BIT0"};
 
 bool exceptionFlag = true;
+extern bool bmcBootCompleteChkPointDone;
+extern bool unProvChkPointStatus;
 
 void init(std::shared_ptr<sdbusplus::asio::connection> conn,
           bool& i2cConfigLoaded)
@@ -525,7 +527,7 @@
     }
 }
 
-int setBMCBootCheckpoint(const uint8_t checkPoint)
+int setBMCBootCompleteChkPoint(const uint8_t checkPoint)
 {
     uint8_t bmcBootCheckpointReg = bmcBootCheckpoint;
 
@@ -557,6 +559,14 @@
         cpldDev.i2cWriteByteData(bmcBootCheckpointReg, checkPoint);
         phosphor::logging::log<phosphor::logging::level::INFO>(
             "Successfully set the PFR CPLD checkpoint 9.");
+        bmcBootCompleteChkPointDone = true;
+        if (unProvChkPointStatus)
+        {
+            unProvChkPointStatus = false;
+            phosphor::logging::log<phosphor::logging::level::INFO>(
+                "PFR is not provisioned, hence exit the service.");
+            std::exit(EXIT_SUCCESS);
+        }
         return 0;
     }
     catch (const std::exception& e)
diff --git a/service/src/mainapp.cpp b/service/src/mainapp.cpp
index 428b0f7..ee21db1 100644
--- a/service/src/mainapp.cpp
+++ b/service/src/mainapp.cpp
@@ -31,7 +31,8 @@
 static int retrCount = 10;
 
 static bool stateTimerRunning = false;
-bool finishedSettingChkPoint = false;
+bool bmcBootCompleteChkPointDone = false;
+bool unProvChkPointStatus = false;
 static constexpr uint8_t bmcBootFinishedChkPoint = 0x09;
 
 std::unique_ptr<boost::asio::steady_timer> stateTimer = nullptr;
@@ -366,10 +367,9 @@
             {
                 phosphor::logging::log<phosphor::logging::level::INFO>(
                     "BMC boot completed. Setting checkpoint 9.");
-                if (!finishedSettingChkPoint)
+                if (!bmcBootCompleteChkPointDone)
                 {
-                    finishedSettingChkPoint = true;
-                    setBMCBootCheckpoint(bmcBootFinishedChkPoint);
+                    setBMCBootCompleteChkPoint(bmcBootFinishedChkPoint);
                 }
                 return;
             }
@@ -422,13 +422,12 @@
         "member='StartupFinished',path='/org/freedesktop/systemd1',"
         "interface='org.freedesktop.systemd1.Manager'",
         [&server, &conn](sdbusplus::message_t& msg) {
-        if (!finishedSettingChkPoint)
+        if (!bmcBootCompleteChkPointDone)
         {
             phosphor::logging::log<phosphor::logging::level::INFO>(
                 "BMC boot completed(StartupFinished). Setting "
                 "checkpoint 9.");
-            finishedSettingChkPoint = true;
-            setBMCBootCheckpoint(bmcBootFinishedChkPoint);
+            setBMCBootCompleteChkPoint(bmcBootFinishedChkPoint);
         }
         });
     checkAndSetCheckpoint(server, conn);
@@ -590,7 +589,8 @@
     return;
 }
 
-void checkPfrInterface(std::shared_ptr<sdbusplus::asio::connection> conn)
+void checkPfrInterface(std::shared_ptr<sdbusplus::asio::connection> conn,
+                       sdbusplus::asio::object_server& server)
 {
     if (!i2cConfigLoaded)
     {
@@ -627,17 +627,15 @@
         }
         else
         {
-            // pfr not supported, stop the service
-            phosphor::logging::log<phosphor::logging::level::INFO>(
-                "PFR not Supported. Hence stop the service");
-            std::exit(EXIT_SUCCESS);
+            unProvChkPointStatus = true;
+            pfr::monitorSignals(server, conn);
         }
     }
 }
 void checkPFRandAddObjects(sdbusplus::asio::object_server& server,
                            std::shared_ptr<sdbusplus::asio::connection>& conn)
 {
-    checkPfrInterface(conn);
+    checkPfrInterface(conn, server);
 
     constexpr size_t timeout = 10; // seconds
     pfrObjTimer->expires_after(std::chrono::seconds(timeout));