futility: deprecate eficompress and efidecompress

I don't think these utilities are needed any longer, so mark them as
deprecated. They will still be built and can be run via futility, but
invoking them directly will fail with a warning message.

BUG=chromium:224734
BRANCH=ToT
TEST=make runtests

Change-Id: Ie704f2cecc3c37c91e4a0ffbcbcf94e2bf3ba05b
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/208775
Reviewed-by: Randall Spangler <rspangler@chromium.org>
diff --git a/Makefile b/Makefile
index fa14a2c..d7742f4 100644
--- a/Makefile
+++ b/Makefile
@@ -534,14 +534,38 @@
 FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
 
 # These are the executables to be replaced with symlinks.
-FUTIL_OLD = bmpblk_font bmpblk_utility cgpt chromeos-tpm-recovery crossystem \
-	dev_debug_vboot dev_make_keypair dev_sign_file dumpRSAPublicKey \
-	dump_fmap dump_kernel_config eficompress efidecompress \
-	enable_dev_usb_boot gbb_utility load_kernel_test \
-	make_dev_firmware.sh make_dev_ssd.sh pad_digest_utility \
-	resign_firmwarefd.sh set_gbb_flags.sh signature_digest_utility \
-	tpm-nvsize tpm_init_temp_fix tpmc vbutil_firmware vbutil_kernel \
-	vbutil_key vbutil_keyblock vbutil_what_keys verify_data
+FUTIL_OLD = \
+	bmpblk_font \
+	bmpblk_utility \
+	cgpt \
+	chromeos-tpm-recovery \
+	crossystem \
+	dev_debug_vboot \
+	dev_make_keypair \
+	dev_sign_file \
+	dumpRSAPublicKey \
+	dump_fmap \
+	dump_kernel_config \
+	eficompress \
+	efidecompress \
+	enable_dev_usb_boot \
+	gbb_utility \
+	load_kernel_test \
+	make_dev_firmware.sh \
+	make_dev_ssd.sh \
+	pad_digest_utility \
+	resign_firmwarefd.sh \
+	set_gbb_flags.sh \
+	signature_digest_utility \
+	tpm-nvsize \
+	tpm_init_temp_fix \
+	tpmc \
+	vbutil_firmware \
+	vbutil_kernel \
+	vbutil_key \
+	vbutil_keyblock \
+	vbutil_what_keys \
+	verify_data
 
 FUTIL_STATIC_SRCS = \
 	futility/futility.c \
diff --git a/firmware/lib/include/vboot_common.h b/firmware/lib/include/vboot_common.h
index 61c7431..83064d2 100644
--- a/firmware/lib/include/vboot_common.h
+++ b/firmware/lib/include/vboot_common.h
@@ -16,11 +16,13 @@
 #endif
 
 /* Test an important condition at compile time, not run time */
+#ifndef BUILD_ASSERT
 #define _BA1_(cond, line) \
 	extern int __build_assertion_ ## line[1 - 2*!(cond)] \
 	__attribute__ ((unused))
 #define _BA0_(c, x) _BA1_(c, x)
 #define BUILD_ASSERT(cond) _BA0_(cond, __LINE__)
+#endif
 
 /* Error Codes for all common functions. */
 enum {
diff --git a/futility/futility.c b/futility/futility.c
index 59145c3..5e852c3 100644
--- a/futility/futility.c
+++ b/futility/futility.c
@@ -79,6 +79,29 @@
 }
 DECLARE_FUTIL_COMMAND(help, do_help, "show a bit of help");
 
+/* Deprecated functions can't be invoked through symlinks. */
+static char *dep_cmds[] = {
+  "eficompress",
+  "efidecompress",
+};
+
+static const char * const dep_usage= "\n\
+The program \"%s\" is deprecated.\n\
+\n\
+If you feel this is in error, please open a bug at\n\
+\n\
+  http://dev.chromium.org/for-testers/bug-reporting-guidelines\n\
+\n\
+In the meantime, you may continue to use the program by invoking it as\n\
+\n\
+  " MYNAME " %s [...]\n\
+\n";
+
+static void deprecated(const char *depname)
+{
+  fprintf(stderr, dep_usage, depname, depname);
+  exit(1);
+}
 
 /******************************************************************************/
 /* Logging stuff */
@@ -214,6 +237,7 @@
   ssize_t r;
   char *s;
   struct futil_cmd_t **cmd;
+  int i;
 
   log_args(argc, argv);
 
@@ -241,6 +265,12 @@
       progname++;
     else
       progname = argv[0];
+  } else {	      /* Invoked by symlink */
+
+	  /* Block any deprecated functions. */
+	  for (i = 0; i < ARRAY_SIZE(dep_cmds); i++)
+		  if (0 == strcmp(dep_cmds[i], progname))
+			  deprecated(progname);
   }
 
   /* See if it's asking for something we know how to do ourselves */
diff --git a/futility/futility.h b/futility/futility.h
index 005a0ce..a1417c0 100644
--- a/futility/futility.h
+++ b/futility/futility.h
@@ -35,4 +35,18 @@
 /* This is the list of pointers to all commands. */
 extern struct futil_cmd_t *futil_cmds[];
 
+/* Size of an array */
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
+#endif
+
+/* Test an important condition at compile time, not run time */
+#ifndef BUILD_ASSERT
+#define _BA1_(cond, line) \
+        extern int __build_assertion_ ## line[1 - 2*!(cond)] \
+        __attribute__ ((unused))
+#define _BA0_(c, x) _BA1_(c, x)
+#define BUILD_ASSERT(cond) _BA0_(cond, __LINE__)
+#endif
+
 #endif /* VBOOT_REFERENCE_FUTILITY_H_ */