vboot2: Allow platform dependent debug logging

TEST=Built with VBOOT_DEBUG on/off. Booted Nyan Blaze. Verified debut output.
BUG=None
BRANCH=none
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>

Change-Id: Id189231f16ca8719dfff0ef3c9a8d4982b741d5f
Reviewed-on: https://chromium-review.googlesource.com/205157
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h
index 7e95d24..4684d54 100644
--- a/firmware/2lib/include/2api.h
+++ b/firmware/2lib/include/2api.h
@@ -372,4 +372,5 @@
 			void *buf,
 			uint32_t size);
 
+void vb2ex_printf(const char *func, const char *fmt, ...);
 #endif  /* VBOOT_2_API_H_ */
diff --git a/firmware/2lib/include/2common.h b/firmware/2lib/include/2common.h
index 326f891..10ecf80 100644
--- a/firmware/2lib/include/2common.h
+++ b/firmware/2lib/include/2common.h
@@ -8,6 +8,7 @@
 #ifndef VBOOT_REFERENCE_VBOOT_2COMMON_H_
 #define VBOOT_REFERENCE_VBOOT_2COMMON_H_
 
+#include "2api.h"
 #include "2return_codes.h"
 #include "2sha.h"
 #include "2struct.h"
@@ -23,13 +24,16 @@
 #endif
 
 /*
- * Debug output.  Defaults to printf(), but can be overridden on a per-platform
- * basis.
+ * Debug output. printf() for tests. otherwise, it's platform-dependent.
  */
-#if defined(VBOOT_DEBUG) && !defined(VB2_DEBUG)
-#define VB2_DEBUG(format, args...) printf(format, ## args)
+#if defined(VBOOT_DEBUG)
+#  if defined(FOR_TEST)
+#    define VB2_DEBUG(format, args...) printf(format, ## args)
+#  else
+#    define VB2_DEBUG(format, args...) vb2ex_printf(__func__, format, ## args)
+#  endif
 #else
-#define VB2_DEBUG(format, args...)
+#  define VB2_DEBUG(format, args...)
 #endif
 
 /* Alignment for work buffer pointers/allocations */