futility: updater: Hacks to allow building futility on Reef

In Reef factory branch the compiler, dependency libraries and default
CFLAGS settings were different so we have to hack for FTW.
Also disable __USE_FILE_OFFSET64 for build breakage by fts.

BUG=b:119292628
TEST=make futil;

Change-Id: I93094d580bb8d28e7f6f8aee5e607a9857da06aa
Reviewed-on: https://chromium-review.googlesource.com/c/1348511
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Commit-Queue: Hung-Te Lin <hungte@chromium.org>
Tested-by: Hung-Te Lin <hungte@chromium.org>
Trybot-Ready: Hung-Te Lin <hungte@chromium.org>
diff --git a/Makefile b/Makefile
index ffc98dd..fe46545 100644
--- a/Makefile
+++ b/Makefile
@@ -1142,6 +1142,7 @@
 .PHONY: futil
 futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
 
+${FUTIL_STATIC_BIN}: LDLIBS += ${CRYPTO_STATIC_LIBS}
 ${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
 	@${PRINTF} "    LD            $(subst ${BUILD}/,,$@)\n"
 	${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
@@ -1256,6 +1257,7 @@
 
 # Some utilities need external crypto functions
 CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
+CRYPTO_STATIC_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto --static)
 
 ${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
 ${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
diff --git a/futility/cmd_gbb_utility.c b/futility/cmd_gbb_utility.c
index f75cceb..0c36932 100644
--- a/futility/cmd_gbb_utility.c
+++ b/futility/cmd_gbb_utility.c
@@ -660,3 +660,5 @@
 
 DECLARE_FUTIL_COMMAND(gbb_utility, do_gbb_utility, VBOOT_VERSION_ALL,
 		      "Manipulate the Google Binary Block (GBB)");
+DECLARE_FUTIL_COMMAND(gbb, do_gbb_utility, VBOOT_VERSION_ALL,
+		      "Manipulate the Google Binary Block (GBB)");
diff --git a/futility/updater.c b/futility/updater.c
index 8922e4a..50c499c 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -6,6 +6,11 @@
  * A reference implementation for AP (and supporting images) firmware updater.
  */
 
+#include "host_common.h"
+#define vb2_unpack_key2(key, packed) \
+	vb2_unpack_key(key, (const uint8_t *)packed, \
+		       packed->key_offset + packed->key_size)
+
 #include <assert.h>
 #include <ctype.h>
 #include <stdio.h>
@@ -1139,7 +1144,7 @@
 		return -1;
 	}
 	vb2_workbuf_init(&wb, workbuf, sizeof(workbuf));
-	if (VB2_SUCCESS != vb2_unpack_key(&key, sign_key)) {
+	if (VB2_SUCCESS != vb2_unpack_key2(&key, sign_key)) {
 		ERROR("Invalid signing key,");
 		return -1;
 	}
diff --git a/futility/updater_archive.c b/futility/updater_archive.c
index 1c8030b..51f735b 100644
--- a/futility/updater_archive.c
+++ b/futility/updater_archive.c
@@ -6,6 +6,9 @@
  * Accessing updater resources from an archive.
  */
 
+#include "host_common.h"
+#undef __USE_FILE_OFFSET64
+
 #include <assert.h>
 #include <ctype.h>
 #include <fts.h>
diff --git a/futility/updater_quirks.c b/futility/updater_quirks.c
index 8c924a3..94bd11a 100644
--- a/futility/updater_quirks.c
+++ b/futility/updater_quirks.c
@@ -6,6 +6,8 @@
  * The board-specific quirks needed by firmware updater.
  */
 
+#include "host_common.h"
+
 #include <assert.h>
 #include <stdio.h>
 #include <string.h>