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/test/flash_erase.c b/test/flash_erase.c
index 3d299dd..ad4e535 100644
--- a/test/flash_erase.c
+++ b/test/flash_erase.c
@@ -13,7 +13,7 @@
 
 #include "common.h"
 #include "mboxd.h"
-#include "flash.h"
+#include "backend.h"
 
 #include "test/tmpf.h"
 
@@ -32,7 +32,7 @@
 	if (rc < 0)
 		return NULL;
 
-	return strdup(mtd.path);
+	return mtd.path;
 }
 
 struct erase_info_user *recorded;
@@ -98,10 +98,13 @@
 
 int main(void)
 {
-	struct mbox_context context;
+	struct mbox_context context = {0};
+	struct backend *backend;
 	char data[MEM_SIZE];
 	int rc;
 
+	backend = &context.backend;
+
 	rc = atexit(cleanup_mtd);
 	if (rc)
 		return rc;
@@ -111,7 +114,7 @@
 	n_ioctls = 0;
 	recorded = NULL;
 
-	flash_dev_init(&context);
+	assert(!backend_probe_mtd(backend, get_dev_mtd()));
 
 	/* Erase from an unknown state */
 	rc = flash_erase(&context, 0, sizeof(data));
@@ -206,7 +209,7 @@
 	recorded = NULL;
 	n_ioctls = 0;
 
-	flash_dev_free(&context);
+	backend_free(backend);
 
 	return rc;
 }