ubi: add tarball as file handler

Add tarball image handler via a generic file handler.

Change-Id: I8902ef27d32a5aeb5112c88e51362f894c1249b3
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/configure.ac b/configure.ac
index 970fca2..c19c858 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,13 @@
 AS_IF([test "x$enable_static_layout" = "xyes"], [
     AX_APPEND_COMPILE_FLAGS([-DENABLE_STATIC_LAYOUT], [CXXFLAGS])
 ])
+# Enable tarball for firmware image staging.
+AC_ARG_ENABLE([tarball-ubi],
+    AS_HELP_STRING([--enable-tarball-ubi],
+                   [Enable tarball firmware update via Blobs]))
+AS_IF([test "x$enanble_tarball_ubi" = "xyes"], [
+    AX_APPEND_COMPILE_FLAGS([-DENABLE_TARBALL_UBI], [CXXFLAGS])
+])
 
 # Enable P2A, and or LPC (block-transfer is always enabled).
 AC_ARG_ENABLE([pci-bridge],
@@ -82,6 +89,10 @@
 AS_IF([test "x$STATIC_HANDLER_STAGED_NAME" == "x"], [STATIC_HANDLER_STAGED_NAME="/run/initramfs/bmc-image"])
 AC_DEFINE_UNQUOTED([STATIC_HANDLER_STAGED_NAME], ["$STATIC_HANDLER_STAGED_NAME"], [The file to use for staging the firmware update.])
 
+AC_ARG_VAR(TARBALL_STAGED_NAME, [The file to use for staging the firmware update.])
+AS_IF([test "x$TARBALL_STAGED_NAME" == "x"], [TARBALL_STAGED_NAME="/tmp/image-update.tar"])
+AC_DEFINE_UNQUOTED([TARBALL_STAGED_NAME], ["$TARBALL_STAGED_NAME"], [The file to use for staging the firmware update.])
+
 AC_ARG_VAR(HASH_FILENAME, [The file to use for the hash provided.])
 AS_IF([test "x$HASH_FILENAME" == "x"], [HASH_FILENAME="/tmp/bmc.sig"])
 AC_DEFINE_UNQUOTED([HASH_FILENAME], ["$HASH_FILENAME"], [The file to use for the hash provided.])
diff --git a/main.cpp b/main.cpp
index 3e4c555..40f4b52 100644
--- a/main.cpp
+++ b/main.cpp
@@ -33,6 +33,7 @@
 {
 FileHandler hashHandler(HASH_FILENAME);
 FileHandler staticLayoutHandler(STATIC_HANDLER_STAGED_NAME);
+FileHandler ubitarballHandler(TARBALL_STAGED_NAME);
 
 #ifdef ENABLE_LPC_BRIDGE
 #if defined(ASPEED_LPC)
@@ -53,6 +54,9 @@
 #ifdef ENABLE_STATIC_LAYOUT
     {"/flash/image", &staticLayoutHandler},
 #endif
+#ifdef ENABLE_TARBALL_UBI
+    {"/flash/tarball", &ubitarballHandler},
+#endif
 };
 
 std::vector<DataHandlerPack> supportedTransports = {