Set Priority value of functional BMC version to 0

The priority values are saved on the BMC flash and in u-boot env
variables as backup, but in the case where both copies are missing
like when the BMC chip is reflashed using a programmer, set the
Priority value of the functional (currently running) BMC version
to 0 to indicate that's the image the BMC booted from.

Resolves openbmc/openbmc#2373

Change-Id: I7cc8a7ae5b1c676891109c71686d7f9b18fde1ca
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index 85fc8ed..3dfa2bc 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -200,6 +200,18 @@
                 createActiveAssociation(path);
             }
 
+            // Create Version instance for this version.
+            auto versionPtr = std::make_unique<VersionClass>(
+                            bus,
+                            path,
+                            version,
+                            purpose,
+                            "");
+            auto isVersionFunctional = versionPtr->isFunctional();
+            versions.insert(std::make_pair(
+                                id,
+                                std::move(versionPtr)));
+
             // Create Activation instance for this version.
             activations.insert(std::make_pair(
                                    id,
@@ -217,8 +229,15 @@
                 uint8_t priority = std::numeric_limits<uint8_t>::max();
                 if (!restoreFromFile(id, priority))
                 {
-                    log<level::ERR>("Unable to restore priority from file.",
-                            entry("VERSIONID=%s", id));
+                    if (isVersionFunctional)
+                    {
+                        priority = 0;
+                    }
+                    else
+                    {
+                        log<level::ERR>("Unable to restore priority from file.",
+                                entry("VERSIONID=%s", id));
+                    }
                 }
                 activations.find(id)->second->redundancyPriority =
                         std::make_unique<RedundancyPriority>(
@@ -227,17 +246,6 @@
                              *(activations.find(id)->second),
                              priority);
             }
-
-            // Create Version instance for this version.
-            versions.insert(std::make_pair(
-                                id,
-                                std::make_unique<
-                                     phosphor::software::manager::Version>(
-                                     bus,
-                                     path,
-                                     version,
-                                     purpose,
-                                     "")));
         }
     }
     return;