vboot2: Move vb2_verify_fw inside of futility

Update the unit tests which use it to use futility.  No functional
changes to it, just relocation.

Remove the futility test which checks the exact list of supported
commands.  This doesn't have a good way of handling
conditionally-compiled commands, and will be even harder to maintain
as we add more commands in the future.  Presence of sub-commands is
still ensured by the other tests which use them (such as
vb2_firmware_tests.sh)

BUG=chromium:231547
BRANCH=none
TEST=make runtests && VBOOT2=1 make runtests

Change-Id: Idddb639276e4c6449d023d40ac7977123113bd28
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/213191
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
diff --git a/Makefile b/Makefile
index fffcfb7..70cf79d 100644
--- a/Makefile
+++ b/Makefile
@@ -490,11 +490,6 @@
 	utility/signature_digest_utility \
 	utility/verify_data
 
-ifneq (${VBOOT2},)
-UTIL_NAMES += \
-	utility/vb2_verify_fw
-endif
-
 endif
 
 UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
@@ -550,6 +545,11 @@
 	futility/cmd_vbutil_key.c \
 	futility/cmd_vbutil_keyblock.c
 
+ifneq (${VBOOT2},)
+FUTIL_SRCS += \
+	futility/cmd_vb2_verify_fw.c
+endif
+
 FUTIL_LDS = futility/futility.lds
 
 FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o}
diff --git a/utility/vb2_verify_fw.c b/futility/cmd_vb2_verify_fw.c
similarity index 93%
rename from utility/vb2_verify_fw.c
rename to futility/cmd_vb2_verify_fw.c
index f7ec0b5..7343d7a 100644
--- a/utility/vb2_verify_fw.c
+++ b/futility/cmd_vb2_verify_fw.c
@@ -11,6 +11,7 @@
 
 #include "2sysincludes.h"
 #include "2api.h"
+#include "futility.h"
 
 const char *progname = "vb2_verify_fw";
 
@@ -133,12 +134,18 @@
 	return VB2_SUCCESS;
 }
 
-int main(int argc, char *argv[])
+int do_vb2_verify_fw(int argc, char *argv[])
 {
 	struct vb2_context ctx;
 	uint8_t workbuf[16384];
 	int rv;
 
+	progname = strrchr(argv[0], '/');
+	if (progname)
+		progname++;
+	else
+		progname = argv[0];
+
 	if (argc < 4) {
 		fprintf(stderr,
 			"usage: %s <gbb> <vblock> <body>\n", progname);
@@ -207,3 +214,6 @@
 
 	return 0;
 }
+
+DECLARE_FUTIL_COMMAND(vb2_verify_fw, do_vb2_verify_fw,
+		      "Verifies firmware using vboot2 library");
diff --git a/tests/futility/test_main.sh b/tests/futility/test_main.sh
index 62177e6..5a09c28 100755
--- a/tests/futility/test_main.sh
+++ b/tests/futility/test_main.sh
@@ -12,22 +12,6 @@
 # No args returns nonzero exit code
 "$FUTILITY" && false
 
-# Make sure all built-in commands are listed and have help
-expected=\
-'dev_sign_file
-dump_fmap
-dump_kernel_config
-gbb_utility
-help
-vbutil_firmware
-vbutil_kernel
-vbutil_key
-vbutil_keyblock'
-got=$("$FUTILITY" help |
-  egrep '^[[:space:]]+[^[:space:]]+[[:space:]]+[^[:space:]]+' |
-  awk '{print $1}')
-[ "$expected" = "$got" ]
-
 # It's weird but okay if the command is a full path.
 "$FUTILITY" /fake/path/to/help  > "$TMP"
 grep Usage "$TMP"
diff --git a/tests/vb2_firmware_tests.sh b/tests/vb2_firmware_tests.sh
index a32dc6d..e1981db 100755
--- a/tests/vb2_firmware_tests.sh
+++ b/tests/vb2_firmware_tests.sh
@@ -52,6 +52,6 @@
 echo 'Verifying test firmware using vb2_verify_fw'
 
 # Verify the firmware using vboot2 utility
-${BIN_DIR}/vb2_verify_fw gbb.test vblock.test body.test
+${BIN_DIR}/futility vb2_verify_fw gbb.test vblock.test body.test
 
 happy 'vb2_verify_fw succeeded'