vboot: deprecate VbExError function

Convert uses of this function to call VB2_DEBUG and manually
exit if necessary.

BUG=b:124141368
TEST=make clean && make runtests
BRANCH=none

Change-Id: I9006b1a9c66645757d33310d96207233b88eaed5
Signed-off-by: Joel Kitching <kitching@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1710340
Tested-by: Joel Kitching <kitching@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Joel Kitching <kitching@chromium.org>
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h
index 6142cfa..518b8cd 100644
--- a/firmware/include/vboot_api.h
+++ b/firmware/include/vboot_api.h
@@ -309,15 +309,6 @@
 VbError_t VbUnlockDevice(void);
 
 /*****************************************************************************/
-/* Debug output (from utility.h) */
-
-/**
- * Output an error message and quit.  Does not return.  Supports
- * printf()-style formatting.
- */
-void VbExError(const char *format, ...);
-
-/*****************************************************************************/
 /* Timer and delay (first two from utility.h) */
 
 #define VB_USEC_PER_MSEC	1000ULL
diff --git a/firmware/lib/include/utility.h b/firmware/lib/include/utility.h
index 10562a5..272b9f4 100644
--- a/firmware/lib/include/utility.h
+++ b/firmware/lib/include/utility.h
@@ -11,13 +11,15 @@
 #ifndef VBOOT_REFERENCE_UTILITY_H_
 #define VBOOT_REFERENCE_UTILITY_H_
 
+#include "2common.h"
 #include "sysincludes.h"
 #include "vboot_api.h"
 
 #ifdef VBOOT_DEBUG
 #define VbAssert(expr) do { if (!(expr)) { \
-	VbExError("assert fail: %s at %s:%d\n", \
-		  #expr, __FILE__, __LINE__); }} while(0)
+	VB2_DEBUG("assert fail: %s at %s:%d\n", \
+		  #expr, __FILE__, __LINE__); \
+	exit(1); }} while(0)
 #else
 #define VbAssert(expr)
 #endif
diff --git a/firmware/stub/vboot_api_stub_init.c b/firmware/stub/vboot_api_stub_init.c
index 23ae9f7..0f7a348 100644
--- a/firmware/stub/vboot_api_stub_init.c
+++ b/firmware/stub/vboot_api_stub_init.c
@@ -15,34 +15,6 @@
 
 #include "vboot_api.h"
 
-/* U-Boot's printf uses '%L' for uint64_t. gcc uses '%l'. */
-#define MAX_FMT 255
-static char fmtbuf[MAX_FMT+1];
-
-static const char *fixfmt(const char *format)
-{
-	int i;
-	for(i=0; i<sizeof(fmtbuf)-1 && format[i]; i++) {
-		fmtbuf[i] = format[i];
-		if(format[i] == '%' && format[i+1] == 'L') {
-			fmtbuf[i+1] = 'l';
-			i++;
-		}
-	}
-	fmtbuf[i] = '\0';
-	return fmtbuf;
-}
-
-void VbExError(const char *format, ...)
-{
-	va_list ap;
-	va_start(ap, format);
-	fprintf(stderr, "ERROR: ");
-	vfprintf(stderr, fixfmt(format), ap);
-	va_end(ap);
-	exit(1);
-}
-
 uint64_t VbExGetTimer(void)
 {
 	struct timeval tv;
diff --git a/host/lib/host_key2.c b/host/lib/host_key2.c
index b33ba16..64aab1b 100644
--- a/host/lib/host_key2.c
+++ b/host/lib/host_key2.c
@@ -44,14 +44,14 @@
 	uint8_t *buf = NULL;
 	uint32_t bufsize = 0;
 	if (VB2_SUCCESS != vb2_read_file(filename, &buf, &bufsize)) {
-		VbExError("unable to read from file %s\n", filename);
+		VB2_DEBUG("unable to read from file %s\n", filename);
 		return NULL;
 	}
 
 	struct vb2_private_key *key =
 		(struct vb2_private_key *)calloc(sizeof(*key), 1);
 	if (!key) {
-		VbExError("Unable to allocate private key\n");
+		VB2_DEBUG("Unable to allocate private key\n");
 		free(buf);
 		return NULL;
 	}
@@ -65,7 +65,7 @@
 		d2i_RSAPrivateKey(0, &start, bufsize - sizeof(alg));
 
 	if (!key->rsa_private_key) {
-		VbExError("Unable to parse RSA private key\n");
+		VB2_DEBUG("Unable to parse RSA private key\n");
 		free(buf);
 		free(key);
 		return NULL;
diff --git a/tests/tpm_lite/tpmtest_enable.c b/tests/tpm_lite/tpmtest_enable.c
index 645cd46..c2fe54b 100644
--- a/tests/tpm_lite/tpmtest_enable.c
+++ b/tests/tpm_lite/tpmtest_enable.c
@@ -8,6 +8,7 @@
 
 #include <stdio.h>
 
+#include "2common.h"
 #include "host_common.h"
 #include "tlcl.h"
 #include "tlcl_tests.h"
@@ -27,7 +28,8 @@
 	TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
 	printf("disable is %d, deactivated is %d\n", disable, deactivated);
 	if (disable == 1 || deactivated == 1) {
-		VbExError("failed to enable or activate");
+		VB2_DEBUG("failed to enable or activate");
+		return 1;
 	}
 	printf("TEST SUCCEEDED\n");
 	return 0;
diff --git a/tests/tpm_lite/tpmtest_writelimit.c b/tests/tpm_lite/tpmtest_writelimit.c
index 66dcc03..cedcd83 100644
--- a/tests/tpm_lite/tpmtest_writelimit.c
+++ b/tests/tpm_lite/tpmtest_writelimit.c
@@ -10,6 +10,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 
+#include "2common.h"
 #include "host_common.h"
 #include "tlcl.h"
 #include "tlcl_tests.h"
@@ -39,8 +40,9 @@
 				VbAssert(i >= TPM_MAX_NV_WRITES_NOOWNER);
 				break;
 			default:
-				VbExError("unexpected error code %d (0x%x)\n",
+				VB2_DEBUG("unexpected error code %d (0x%x)\n",
 					  result, result);
+				exit(1);
 			}
 		}
 	}