reboot-cause: look for pinhole reset first

A pinhole reset is usually a users last try and recovering a hung
system. On some systems, a pinhole reset will result in both a BMC reset
and a power off to the chassis. Need to ensure the real reason is
recorded so look for the pinhole reset first before looking to see if an
AC loss has occurred.

Testing:
- None, logic seems fairly obvious

Change-Id: I51f41620df2a2f99469ec8fdcba2e464a7711d82
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/bmc_state_manager.cpp b/bmc_state_manager.cpp
index 006972c..e418879 100644
--- a/bmc_state_manager.cpp
+++ b/bmc_state_manager.cpp
@@ -295,15 +295,6 @@
             break;
     }
 
-    // If the above code could not detect a reason, check to see
-    // if an AC loss occured.
-    size_t chassisId = 0;
-    if (phosphor::state::manager::utils::checkACLoss(chassisId))
-    {
-        this->lastRebootCause(RebootCause::POR);
-        return;
-    }
-
     // If the above code could not detect a reason, look for a the
     // reset-cause-pinhole gpio to see if it is the reason for the reboot
     auto gpioval =
@@ -321,6 +312,17 @@
             this->bus, errorMsg,
             sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level::
                 Notice);
+        return;
+    }
+
+    // If we still haven't found a reason, see if we lost AC power
+    // Note that a pinhole reset will remove AC power to the chassis
+    // on some systems so we always want to look for the pinhole reset
+    // first as that would be the main reason AC power was lost.
+    size_t chassisId = 0;
+    if (phosphor::state::manager::utils::checkACLoss(chassisId))
+    {
+        this->lastRebootCause(RebootCause::POR);
     }
 
     return;