vpnor: add API to get partition entry by name
Change-Id: I1f86c646c6629a6a42788821e469d36f55c92264
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index 59146ba..af44432 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -141,7 +141,10 @@
$(TEST_MBOX_VPNOR_SRCS) \
test/create_pnor_partition_table.cpp
test_create_pnor_partition_table_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
-test_create_pnor_partition_table_LDADD = -lstdc++fs
+test_create_pnor_partition_table_LDADD = -lstdc++fs \
+ $(SDBUSPLUS_LIBS) \
+ $(PHOSPHOR_LOGGING_LIBS) \
+ $(PHOSPHOR_DBUS_INTERFACES_LIBS)
test_create_read_window_vpnor_SOURCES = \
$(TEST_MBOX_VPNOR_SRCS) $(TEST_MOCK_SRCS) \
diff --git a/pnor_partition_table.cpp b/pnor_partition_table.cpp
index 1168d2d..36f0765 100644
--- a/pnor_partition_table.cpp
+++ b/pnor_partition_table.cpp
@@ -1,6 +1,8 @@
#include "pnor_partition_table.hpp"
#include "common.h"
#include "config.h"
+#include "xyz/openbmc_project/Common/error.hpp"
+#include <phosphor-logging/elog-errors.hpp>
#include <syslog.h>
#include <endian.h>
#include <regex>
@@ -12,6 +14,9 @@
namespace virtual_pnor
{
+using namespace phosphor::logging;
+using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+
namespace partition
{
@@ -192,6 +197,24 @@
return p;
}
+const pnor_partition& Table::partition(const std::string& name) const
+{
+ const decltype(auto) table = getNativeTable();
+
+ for (decltype(numParts) i{}; i < numParts; ++i)
+ {
+ if (name == table.partitions[i].data.name)
+ {
+ return table.partitions[i];
+ }
+ }
+
+ MSG_ERR("Partition %s not found", name.c_str());
+ elog<InternalFailure>();
+ static pnor_partition p{};
+ return p;
+}
+
} // namespace partition
PartitionTable endianFixup(const PartitionTable& in)
diff --git a/pnor_partition_table.hpp b/pnor_partition_table.hpp
index d933b67..23cb9f5 100644
--- a/pnor_partition_table.hpp
+++ b/pnor_partition_table.hpp
@@ -139,6 +139,15 @@
*/
const pnor_partition& partition(size_t offset) const;
+ /** @brief Return partition corresponding to input partition name.
+ *
+ * @param[in] name - PNOR partition name
+ *
+ * @returns const reference to pnor_partition, if found, else an
+ * exception will be thrown.
+ */
+ const pnor_partition& partition(const std::string& name) const;
+
private:
/** @brief Prepares a vector of PNOR partition structures.
*/