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/implicit_flush.c b/test/implicit_flush.c
index 74275e4..f186d19 100644
--- a/test/implicit_flush.c
+++ b/test/implicit_flush.c
@@ -5,6 +5,7 @@
 #include <sys/mman.h>
 
 #include "mboxd.h"
+#include "mtd/backend.h"
 #include "transport_mbox.h"
 
 #include "test/mbox.h"
@@ -92,7 +93,7 @@
 	assert(rc == 0);
 
 	map = mmap(NULL, MEM_SIZE, PROT_READ, MAP_PRIVATE,
-			ctx->fds[MTD_FD].fd, 0);
+			((struct mtd_data *)ctx->backend.priv)->fd, 0);
 	assert(map != MAP_FAILED);
 
 	rc = memcmp(finish_data, map, sizeof(finish_data));
@@ -124,7 +125,7 @@
 	assert(rc == 0);
 
 	map = mmap(NULL, MEM_SIZE, PROT_READ, MAP_PRIVATE,
-			ctx->fds[MTD_FD].fd, 0);
+			((struct mtd_data *)ctx->backend.priv)->fd, 0);
 	assert(map != MAP_FAILED);
 
 	rc = memcmp(finish_data, map, sizeof(finish_data));