summaryrefslogtreecommitdiffstats
path: root/serialize.cpp
diff options
context:
space:
mode:
authorMichael Tritz <mtritz@us.ibm.com>2017-07-29 23:32:21 -0500
committerMichael Tritz <mtritz@us.ibm.com>2017-07-30 15:27:12 -0500
commit60bc20fe36517be7c7ae4f2aac976ed3dd6acdc2 (patch)
tree7a27f078d4a9fa4bc10316b855383da4ec0c371c /serialize.cpp
parent4c5d744346499a927eee0ef0e1adb5218b33cc01 (diff)
downloadopenpower-pnor-code-mgmt-60bc20fe36517be7c7ae4f2aac976ed3dd6acdc2.tar.gz
openpower-pnor-code-mgmt-60bc20fe36517be7c7ae4f2aac976ed3dd6acdc2.zip
PNOR: Restore RedundancyPriority on reset
This commit extends the functionality of the PNOR 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/openpower-pnor-code-mgmt/ using the Cereal library. Each time a priority value is modified, the value in the corresponding version file is adjusted. When the item updater resets, it reads back the priority values from these files. Resolves openbmc/openbmc#2040 Change-Id: I908431801e541a1e5b39bcf49ae057f7e340eecc Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
Diffstat (limited to 'serialize.cpp')
-rw-r--r--serialize.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/serialize.cpp b/serialize.cpp
new file mode 100644
index 000000000..e2e8bfd22
--- /dev/null
+++ b/serialize.cpp
@@ -0,0 +1,51 @@
+#include "config.h"
+#include <experimental/filesystem>
+#include <cereal/archives/binary.hpp>
+#include <fstream>
+#include "serialize.hpp"
+
+namespace openpower
+{
+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(), std::ios::binary);
+ cereal::BinaryOutputArchive oarchive(os);
+ oarchive(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 | std::ios::binary);
+ cereal::BinaryInputArchive iarchive(is);
+ iarchive(*priority);
+ }
+}
+
+void removeFile(std::string versionId)
+{
+ std::string path = PERSIST_DIR + versionId;
+ if (fs::exists(path))
+ {
+ fs::remove(path);
+ }
+}
+
+} // namespace updater
+} // namespace software
+} // namespace openpower
OpenPOWER on IntegriCloud