mboxd: Add a backend abstraction layer to mboxd.
Introduce a backend abstraction, enabling multiple implementations to be
compiled in at once. This change formally abstracts the two existing
backends, mtd and vpnor.
With the backend abstraction in place, subsequent backends are easier to
implement.
This change is based of Evan's work and he retains authorship credit. I
(AJ) have reworked the patch to pass the vpnor tests, refactored some
parts to enable broader use of const structures and others to clarify
the initialisation sequences.
Due to the existing lack of abstraction the patch has unfortunately
wide-ranging impacts. I've whittled it down as much as I consider
reasonable.
Change-Id: I29984a36dae4ea86ec00b853d2a756f0b9afb3ec
Signed-off-by: Evan Lojewski <github@meklort.com>
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/vpnor/pnor_partition.cpp b/vpnor/pnor_partition.cpp
index 613ee26..9854159 100644
--- a/vpnor/pnor_partition.cpp
+++ b/vpnor/pnor_partition.cpp
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
extern "C" {
-#include "flash.h"
+#include "mboxd.h"
}
#include "config.h"
@@ -39,8 +39,10 @@
fs::path Request::getPartitionFilePath(int flags)
{
+ struct vpnor_data* priv = (struct vpnor_data*)backend->priv;
+
// Check if partition exists in patch location
- auto dst = fs::path(ctx->paths.patch_loc) / partition.data.name;
+ auto dst = fs::path(priv->paths.patch_loc) / partition.data.name;
if (fs::is_regular_file(dst))
{
return dst;
@@ -50,15 +52,15 @@
(PARTITION_PRESERVED | PARTITION_READONLY))
{
case PARTITION_PRESERVED:
- dst = ctx->paths.prsv_loc;
+ dst = priv->paths.prsv_loc;
break;
case PARTITION_READONLY:
- dst = ctx->paths.ro_loc;
+ dst = priv->paths.ro_loc;
break;
default:
- dst = ctx->paths.rw_loc;
+ dst = priv->paths.rw_loc;
}
dst /= partition.data.name;
@@ -69,22 +71,22 @@
if (flags == O_RDONLY)
{
- dst = fs::path(ctx->paths.ro_loc) / partition.data.name;
+ dst = fs::path(priv->paths.ro_loc) / partition.data.name;
assert(fs::exists(dst));
return dst;
}
assert(flags == O_RDWR);
- auto src = fs::path(ctx->paths.ro_loc) / partition.data.name;
+ auto src = fs::path(priv->paths.ro_loc) / partition.data.name;
assert(fs::exists(src));
MSG_DBG("RWRequest: Didn't find '%s' under '%s', copying from '%s'\n",
partition.data.name, dst.c_str(), src.c_str());
- dst = ctx->paths.rw_loc;
+ dst = priv->paths.rw_loc;
if (partition.data.user.data[1] & PARTITION_PRESERVED)
{
- dst = ctx->paths.prsv_loc;
+ dst = priv->paths.prsv_loc;
}
dst /= partition.data.name;
@@ -96,7 +98,7 @@
size_t Request::clamp(size_t len)
{
size_t maxAccess = offset + len;
- size_t partSize = partition.data.size << ctx->block_size_shift;
+ size_t partSize = partition.data.size << backend->block_size_shift;
return std::min(maxAccess, partSize) - offset;
}
@@ -168,7 +170,7 @@
else
{
memcpy((char*)map + offset, buf, len);
- flash_set_bytemap(ctx, base + offset, len, FLASH_DIRTY);
+ backend_set_bytemap(backend, base + offset, len, FLASH_DIRTY);
}
munmap(map, fileSize);
close(fd);