pnor_partition_table: Make parseTocLine throw exceptions
Change-Id: I66dc8af4fede36c3c952df596040356e11a72644
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/mboxd_pnor_partition_table.cpp b/mboxd_pnor_partition_table.cpp
index 84a0314..40d2ea6 100644
--- a/mboxd_pnor_partition_table.cpp
+++ b/mboxd_pnor_partition_table.cpp
@@ -13,31 +13,53 @@
openpower::virtual_pnor::partition::Table *table = nullptr;
};
-void init_vpnor(struct mbox_context *context)
+int init_vpnor(struct mbox_context *context)
{
if (context && !context->vpnor)
{
+ int rc;
+
strcpy(context->paths.ro_loc, PARTITION_FILES_RO_LOC);
strcpy(context->paths.rw_loc, PARTITION_FILES_RW_LOC);
strcpy(context->paths.prsv_loc, PARTITION_FILES_PRSV_LOC);
strcpy(context->paths.patch_loc, PARTITION_FILES_PATCH_LOC);
- vpnor_create_partition_table_from_path(context, PARTITION_FILES_RO_LOC);
+ rc = vpnor_create_partition_table_from_path(context,
+ PARTITION_FILES_RO_LOC);
+ if (rc < 0)
+ return rc;
}
+
+ return 0;
}
-void vpnor_create_partition_table_from_path(struct mbox_context *context,
- const char *path)
+int vpnor_create_partition_table_from_path(struct mbox_context *context,
+ const char *path)
{
- std::experimental::filesystem::path dir(path);
+ namespace err = sdbusplus::xyz::openbmc_project::Common::Error;
+ namespace fs = std::experimental::filesystem;
+ namespace vpnor = openpower::virtual_pnor;
if (context && !context->vpnor)
{
- context->vpnor = new vpnor_partition_table;
- context->vpnor->table = new openpower::virtual_pnor::partition::Table(
- std::move(dir), 1 << context->erase_size_shift,
- context->flash_size);
+ fs::path dir(path);
+ try
+ {
+ context->vpnor = new vpnor_partition_table;
+ context->vpnor->table =
+ new openpower::virtual_pnor::partition::Table(
+ std::move(dir), 1 << context->erase_size_shift,
+ context->flash_size);
+ }
+ catch (vpnor::TocEntryError &e)
+ {
+ MSG_ERR("%s\n", e.what());
+ phosphor::logging::commit<err::InternalFailure>();
+ return -MBOX_R_SYSTEM_ERROR;
+ }
}
+
+ return 0;
}
size_t vpnor_get_partition_table_size(const struct mbox_context *context)
@@ -60,7 +82,7 @@
: nullptr;
}
-void vpnor_copy_bootloader_partition(const struct mbox_context *context)
+int vpnor_copy_bootloader_partition(const struct mbox_context *context)
{
// The hostboot bootloader has certain size/offset assumptions, so
// we need a special partition table here.
@@ -76,26 +98,28 @@
constexpr size_t tocMaxSize = 0x8000;
constexpr size_t tocStart = pnorSize - tocMaxSize - pageSize;
constexpr auto blPartitionName = "HBB";
+
+ namespace err = sdbusplus::xyz::openbmc_project::Common::Error;
namespace fs = std::experimental::filesystem;
+ namespace vpnor = openpower::virtual_pnor;
- openpower::virtual_pnor::partition::Table blTable(
- fs::path{PARTITION_FILES_RO_LOC}, eraseSize, pnorSize);
-
- vpnor_partition_table vtbl{};
- vtbl.table = &blTable;
- struct mbox_context local
- {
- };
- local.vpnor = &vtbl;
- local.block_size_shift = log_2(eraseSize);
- memcpy(&local.paths, &context->paths, sizeof(local.paths));
-
- size_t tocOffset = 0;
- uint32_t tocSize = blTable.size() * eraseSize;
- using namespace phosphor::logging;
- using namespace sdbusplus::xyz::openbmc_project::Common::Error;
try
{
+ openpower::virtual_pnor::partition::Table blTable(
+ fs::path{PARTITION_FILES_RO_LOC}, eraseSize, pnorSize);
+
+ vpnor_partition_table vtbl{};
+ vtbl.table = &blTable;
+ struct mbox_context local
+ {
+ };
+ local.vpnor = &vtbl;
+ local.block_size_shift = log_2(eraseSize);
+ memcpy(&local.paths, &context->paths, sizeof(local.paths));
+
+ size_t tocOffset = 0;
+ uint32_t tocSize = blTable.size() * eraseSize;
+
// Copy TOC
copy_flash(&local, tocOffset,
static_cast<uint8_t *>(context->mem) + tocStart, tocSize);
@@ -106,10 +130,19 @@
copy_flash(&local, hbbOffset,
static_cast<uint8_t *>(context->mem) + hbbOffset, hbbSize);
}
- catch (InternalFailure &e)
+ catch (err::InternalFailure &e)
{
- commit<InternalFailure>();
+ phosphor::logging::commit<err::InternalFailure>();
+ return -MBOX_R_SYSTEM_ERROR;
}
+ catch (vpnor::TocEntryError &e)
+ {
+ MSG_ERR("%s\n", e.what());
+ phosphor::logging::commit<err::InternalFailure>();
+ return -MBOX_R_SYSTEM_ERROR;
+ }
+
+ return 0;
}
void destroy_vpnor(struct mbox_context *context)