Add per platform mcuboot_logging.h files

New logging macros were added for all supported platforms, following the
documentation defined in the template config file.

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/zephyr/Kconfig b/boot/zephyr/Kconfig
index 87664ec..10eb22d 100644
--- a/boot/zephyr/Kconfig
+++ b/boot/zephyr/Kconfig
@@ -78,6 +78,15 @@
 
 	  This is not available for all targets.
 
+config BOOT_HAVE_LOGGING
+	bool "MCUboot have logging enabled"
+	default y
+	select SYS_LOG
+	help
+	  If y, enables logging on the serial port. The log level can
+	  be defined by setting `SYS_LOG_DEFAULT_LEVEL`.
+	  If unsure, leave at the default value.
+
 menuconfig MCUBOOT_SERIAL
 	bool "MCUboot serial recovery"
 	default n
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
index 0b65cd0..97a0f85 100644
--- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
@@ -39,6 +39,10 @@
 #define MCUBOOT_OVERWRITE_ONLY_FAST
 #endif
 
+#ifdef CONFIG_BOOT_HAVE_LOGGING
+#define MCUBOOT_HAVE_LOGGING 1
+#endif
+
 /*
  * Enabling this option uses newer flash map APIs. This saves RAM and
  * avoids deprecated API usage.
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_logging.h b/boot/zephyr/include/mcuboot_config/mcuboot_logging.h
new file mode 100644
index 0000000..8ee5378
--- /dev/null
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_logging.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2018 Runtime Inc
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef __MCUBOOT_LOGGING_H__
+#define __MCUBOOT_LOGGING_H__
+
+#ifndef __BOOTSIM__
+
+/*
+ * When building for targets running Zephyr, delegate to its native
+ * logging subsystem.
+ *
+ * In this case:
+ *
+ * - MCUBOOT_LOG_LEVEL determines SYS_LOG_LEVEL,
+ * - MCUBOOT_LOG_ERR() and friends are SYS_LOG_ERR() etc.
+ * - SYS_LOG_DOMAIN is unconditionally set to "MCUBOOT"
+ */
+#define MCUBOOT_LOG_LEVEL_OFF      SYS_LOG_LEVEL_OFF
+#define MCUBOOT_LOG_LEVEL_ERROR    SYS_LOG_LEVEL_ERROR
+#define MCUBOOT_LOG_LEVEL_WARNING  SYS_LOG_LEVEL_WARNING
+#define MCUBOOT_LOG_LEVEL_INFO     SYS_LOG_LEVEL_INFO
+#define MCUBOOT_LOG_LEVEL_DEBUG    SYS_LOG_LEVEL_DEBUG
+
+/* Treat MCUBOOT_LOG_LEVEL equivalently to SYS_LOG_LEVEL. */
+#ifndef MCUBOOT_LOG_LEVEL
+#define MCUBOOT_LOG_LEVEL CONFIG_SYS_LOG_DEFAULT_LEVEL
+#elif (MCUBOOT_LOG_LEVEL < CONFIG_SYS_LOG_OVERRIDE_LEVEL)
+#undef MCUBOOT_LOG_LEVEL
+#define MCUBOOT_LOG_LEVEL CONFIG_SYS_LOG_OVERRIDE_LEVEL
+#endif
+
+#define SYS_LOG_LEVEL MCUBOOT_LOG_LEVEL
+
+#undef SYS_LOG_DOMAIN
+#define SYS_LOG_DOMAIN "MCUBOOT"
+
+#define MCUBOOT_LOG_ERR(...) SYS_LOG_ERR(__VA_ARGS__)
+#define MCUBOOT_LOG_WRN(...) SYS_LOG_WRN(__VA_ARGS__)
+#define MCUBOOT_LOG_INF(...) SYS_LOG_INF(__VA_ARGS__)
+#define MCUBOOT_LOG_DBG(...) SYS_LOG_DBG(__VA_ARGS__)
+
+#include <logging/sys_log.h>
+
+#endif /* !__BOOTSIM__ */
+
+#endif /* __MCUBOOT_LOGGING_H__ */