2lib: create generic return code for unimplemented external functions

vboot_reference has a set of "external" functions which are
defined by the client and linked in at compile time.

Instead of creating a separate return code for each unimplemented
external function, group them all into one.

BUG=chromium:944804
TEST=make clean && make runtests
BRANCH=None

Change-Id: Ic3896572c71aabf99590758c7fc3848b61f9e078
Reviewed-on: https://chromium-review.googlesource.com/1539433
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Joel Kitching <kitching@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
diff --git a/firmware/2lib/2stub.c b/firmware/2lib/2stub.c
index e3489cf..417c06e 100644
--- a/firmware/2lib/2stub.c
+++ b/firmware/2lib/2stub.c
@@ -27,7 +27,8 @@
 __attribute__((weak))
 int vb2ex_tpm_clear_owner(struct vb2_context *ctx)
 {
-	return VB2_ERROR_EX_TPM_CLEAR_OWNER_UNIMPLEMENTED;
+	fprintf(stderr, "%s: function not implemented", __func__);
+	return VB2_ERROR_EX_UNIMPLEMENTED;
 }
 
 __attribute__((weak))
@@ -37,7 +38,8 @@
 			void *buf,
 			uint32_t size)
 {
-	return VB2_ERROR_EX_READ_RESOURCE_UNIMPLEMENTED;
+	fprintf(stderr, "%s: function not implemented", __func__);
+	return VB2_ERROR_EX_UNIMPLEMENTED;
 }
 
 __attribute__((weak))
@@ -51,18 +53,19 @@
 int vb2ex_hwcrypto_digest_extend(const uint8_t *buf,
 				 uint32_t size)
 {
-	return VB2_ERROR_SHA_EXTEND_ALGORITHM;	/* Should not be called. */
+	return VB2_ERROR_SHA_EXTEND_ALGORITHM;  /* Should not be called. */
 }
 
 __attribute__((weak))
 int vb2ex_hwcrypto_digest_finalize(uint8_t *digest,
 				   uint32_t digest_size)
 {
-	return VB2_ERROR_SHA_FINALIZE_ALGORITHM; /* Should not be called. */
+	return VB2_ERROR_SHA_FINALIZE_ALGORITHM;  /* Should not be called. */
 }
 
 __attribute__((weak))
 int vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val)
 {
-	return VB2_ERROR_UNKNOWN;
+	fprintf(stderr, "%s: function not implemented", __func__);
+	return VB2_ERROR_EX_UNIMPLEMENTED;
 }
diff --git a/firmware/2lib/include/2return_codes.h b/firmware/2lib/include/2return_codes.h
index 3cc0101..92e4eb1 100644
--- a/firmware/2lib/include/2return_codes.h
+++ b/firmware/2lib/include/2return_codes.h
@@ -588,8 +588,9 @@
 	 */
 	VB2_ERROR_EX = VB2_ERROR_BASE + 0x0a0000,
 
-	/* Read resource not implemented */
-	VB2_ERROR_EX_READ_RESOURCE_UNIMPLEMENTED,
+	/* Read resource not implemented
+	 * Deprecated: use VB2_ERROR_EX_UNIMPLEMENTED (chromium:944804) */
+	VB2_ERROR_EX_DEPRECATED_READ_RESOURCE_UNIMPLEMENTED,
 
 	/* Resource index not found */
 	VB2_ERROR_EX_READ_RESOURCE_INDEX,
@@ -600,8 +601,9 @@
 	/* TPM clear owner failed */
 	VB2_ERROR_EX_TPM_CLEAR_OWNER,
 
-	/* TPM clear owner not implemented */
-	VB2_ERROR_EX_TPM_CLEAR_OWNER_UNIMPLEMENTED,
+	/* TPM clear owner not implemented
+	 * Deprecated: use VB2_ERROR_EX_UNIMPLEMENTED (chromium:944804) */
+	VB2_ERROR_DEPRECATED_EX_TPM_CLEAR_OWNER_UNIMPLEMENTED,
 
 	/* Hardware crypto engine doesn't support this algorithm (non-fatal) */
 	VB2_ERROR_EX_HWCRYPTO_UNSUPPORTED,
@@ -609,6 +611,9 @@
 	/* TPM does not understand this command */
 	VB2_ERROR_EX_TPM_NO_SUCH_COMMAND,
 
+	/* vb2ex function is unimplemented (stubbed in 2lib/2stub.c) */
+	VB2_ERROR_EX_UNIMPLEMENTED,
+
 	/**********************************************************************
 	 * Errors generated by host library (non-firmware) start here.
 	 */