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/test/Makefile.am.include b/vpnor/test/Makefile.am.include
index 5ff4dcc..0600969 100644
--- a/vpnor/test/Makefile.am.include
+++ b/vpnor/test/Makefile.am.include
@@ -1,7 +1,4 @@
-TEST_MBOX_VPNOR_SRCS = \
-	common.c \
-	vpnor/pnor_partition_table.cpp \
-	%reldir%/tmpd.cpp
+TEST_MOCK_VPNOR_SRCS = $(TEST_MOCK_CORE)
 
 TEST_MBOX_VPNOR_INTEG_SRCS = \
 	common.c \
@@ -9,9 +6,8 @@
 	transport_mbox.c \
 	windows.c \
 	lpc.c \
-	vpnor/lpc_reset.cpp \
+	vpnor/backend.cpp \
 	vpnor/mboxd_pnor_partition_table.cpp \
-	vpnor/flash.cpp \
 	vpnor/pnor_partition.cpp \
 	vpnor/pnor_partition_table.cpp \
 	%reldir%/tmpd.cpp
@@ -22,14 +18,14 @@
 	$(PHOSPHOR_DBUS_INTERFACES_LIBS)
 
 vpnor_test_create_pnor_partition_table_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_pnor_partition_table.cpp
 vpnor_test_create_pnor_partition_table_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_create_pnor_partition_table_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_create_read_window_partition_exists_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_read_window_partition_exists.cpp
 vpnor_test_create_read_window_partition_exists_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
@@ -106,63 +102,63 @@
 vpnor_test_toc_flags_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_toc_overlap_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/toc_overlap.cpp
 vpnor_test_toc_overlap_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_toc_overlap_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_toc_lookup_found_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/toc_lookup_found.cpp
 vpnor_test_toc_lookup_found_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_toc_lookup_found_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_toc_lookup_failed_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/toc_lookup_failed.cpp
 vpnor_test_toc_lookup_failed_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_toc_lookup_failed_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_toc_missing_file_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/toc_missing_file.cpp
 vpnor_test_toc_missing_file_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_toc_missing_file_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_create_read_window_oob_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_read_window_oob.cpp
 vpnor_test_create_read_window_oob_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_create_read_window_oob_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_create_read_window_toc_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_read_window_toc.cpp
 vpnor_test_create_read_window_toc_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_create_read_window_toc_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_create_read_window_straddle_partitions_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_read_window_straddle_partitions.cpp
 vpnor_test_create_read_window_straddle_partitions_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_create_read_window_straddle_partitions_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_create_read_window_partition_invalid_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_read_window_partition_invalid.cpp
 vpnor_test_create_read_window_partition_invalid_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_create_read_window_partition_invalid_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_read_patch_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/read_patch.cpp
 vpnor_test_read_patch_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
@@ -176,56 +172,56 @@
 vpnor_test_write_patch_resize_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_dump_flash_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/dump_flash.cpp
 vpnor_test_dump_flash_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_dump_flash_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_create_read_window_size_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_read_window_size.cpp
 vpnor_test_create_read_window_size_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_create_read_window_size_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_create_read_window_remap_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_read_window_remap.cpp
 vpnor_test_create_read_window_remap_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_create_read_window_remap_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_create_write_window_ro_partition_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_write_window_ro_partition.cpp
 vpnor_test_create_write_window_ro_partition_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_create_write_window_ro_partition_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_create_write_window_rw_partition_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_write_window_rw_partition.cpp
 vpnor_test_create_write_window_rw_partition_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_create_write_window_rw_partition_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_create_write_window_unmapped_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/create_write_window_unmapped.cpp
 vpnor_test_create_write_window_unmapped_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_create_write_window_unmapped_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_write_toc_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/write_toc.cpp
 vpnor_test_write_toc_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
 vpnor_test_write_toc_LDADD = $(VPNOR_LDADD)
 
 vpnor_test_force_readonly_toc_SOURCES = \
-	$(TEST_MOCK_SRCS) \
+	$(TEST_MOCK_VPNOR_SRCS) \
 	$(TEST_MBOX_VPNOR_INTEG_SRCS) \
 	%reldir%/force_readonly_toc.cpp
 vpnor_test_force_readonly_toc_LDFLAGS = $(OESDK_TESTCASE_FLAGS)