BMC: Store RedundancyPriority on System.

This commit extends the functionality of the BMC software updater by
preserving RedundancyPriority values through any kind of reset.

This is accomplished by storing priority values in serial files in
/var/lib/obmc/phosphor-bmc-code-mgmt/ using the Cereal library. Each
time a priority value is modified, the value in the corresponding
version file is adjusted.

Resolves openbmc/openbmc#2125

Change-Id: Ie697279895bc5ff5fdef31fa88c78dc2bc63390a
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/serialize.cpp b/serialize.cpp
new file mode 100644
index 0000000..8c97c89
--- /dev/null
+++ b/serialize.cpp
@@ -0,0 +1,51 @@
+#include "config.h"
+#include <experimental/filesystem>
+#include <cereal/archives/json.hpp>
+#include <fstream>
+#include "serialize.hpp"
+
+namespace phosphor
+{
+namespace software
+{
+namespace updater
+{
+
+namespace fs = std::experimental::filesystem;
+
+void storeToFile(std::string versionId, uint8_t priority)
+{
+    if(!fs::is_directory(PERSIST_DIR))
+    {
+        fs::create_directory(PERSIST_DIR);
+    }
+    std::string path = PERSIST_DIR + versionId;
+
+    std::ofstream os(path.c_str());
+    cereal::JSONOutputArchive oarchive(os);
+    oarchive(cereal::make_nvp("priority", priority));
+}
+
+void restoreFromFile(std::string versionId, uint8_t& priority)
+{
+    std::string path = PERSIST_DIR + versionId;
+    if (fs::exists(path))
+    {
+        std::ifstream is(path.c_str(), std::ios::in);
+        cereal::JSONInputArchive iarchive(is);
+        iarchive(cereal::make_nvp("priority", priority));
+    }
+}
+
+void removeFile(std::string versionId)
+{
+    std::string path = PERSIST_DIR + versionId;
+    if (fs::exists(path))
+    {
+        fs::remove(path);
+    }
+}
+
+} // namespace phosphor
+} // namespace software
+} // namespace openpower