BMC: Update u-boot environment variable based on lowest priority

- If a BMC is set to the lowest priority then update the u-boot
  environment variables so that that system boots from that version
  on the next reboot.

Resolves openbmc/openbmc#2284

Change-Id: If0b67b07496f602fa06607bd0685d6394cb8d9fd
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index 34096df..a19aebc 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -323,14 +323,15 @@
     return ItemUpdater::ActivationStatus::ready;
 }
 
-void ItemUpdater::freePriority(uint8_t value)
+void ItemUpdater::freePriority(uint8_t value, const std::string& versionId)
 {
     //TODO openbmc/openbmc#1896 Improve the performance of this function
     for (const auto& intf : activations)
     {
         if (intf.second->redundancyPriority)
         {
-            if (intf.second->redundancyPriority.get()->priority() == value)
+            if (intf.second->redundancyPriority.get()->priority() == value &&
+                intf.second->versionId != versionId)
             {
                 intf.second->redundancyPriority.get()->priority(value + 1);
             }
@@ -500,6 +501,21 @@
     }
 }
 
+bool ItemUpdater::isLowestPriority(uint8_t value)
+{
+    for (const auto& intf : activations)
+    {
+        if(intf.second->redundancyPriority)
+        {
+            if (intf.second->redundancyPriority.get()->priority() < value)
+            {
+                return false;
+            }
+        }
+    }
+    return true;
+}
+
 } // namespace updater
 } // namespace software
 } // namespace phosphor