Fix serial boot functionality for Mynewt

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/boot_serial/pkg.yml b/boot/boot_serial/pkg.yml
index 2cc72a8..9fa5acf 100644
--- a/boot/boot_serial/pkg.yml
+++ b/boot/boot_serial/pkg.yml
@@ -26,14 +26,14 @@
     - bootloader
 
 pkg.deps:
-    - hw/hal
-    - kernel/os
-    - boot/bootutil
-    - encoding/tinycbor
-    - encoding/cborattr
-    - encoding/base64
-    - sys/flash_map
-    - util/crc
+    - "@apache-mynewt-core/hw/hal"
+    - "@apache-mynewt-core/kernel/os"
+    - "@apache-mynewt-core/encoding/tinycbor"
+    - "@apache-mynewt-core/encoding/cborattr"
+    - "@apache-mynewt-core/encoding/base64"
+    - "@apache-mynewt-core/sys/flash_map"
+    - "@apache-mynewt-core/util/crc"
 
 pkg.req_apis:
     - console
+    - bootloader
diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c
index db6388e..5a0332a 100644
--- a/boot/boot_serial/src/boot_serial.c
+++ b/boot/boot_serial/src/boot_serial.c
@@ -24,6 +24,9 @@
 
 #include "sysflash/sysflash.h"
 
+#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_INFO
+#include "bootutil/bootutil_log.h"
+
 #ifdef __ZEPHYR__
 #include <misc/reboot.h>
 #include <misc/byteorder.h>
@@ -31,9 +34,6 @@
 #include <flash.h>
 #include <crc16.h>
 #include <serial_adapter/serial_adapter.h>
-
-#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_INFO
-#include "bootutil/bootutil_log.h"
 #include "mbedtls/base64.h"
 #else
 #include <bsp/bsp.h>
diff --git a/boot/boot_serial/syscfg.yml b/boot/boot_serial/syscfg.yml
new file mode 100644
index 0000000..84fc39f
--- /dev/null
+++ b/boot/boot_serial/syscfg.yml
@@ -0,0 +1,47 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.defs:
+    BOOT_SERIAL_DETECT_PIN:
+        description: >
+            Start the serial boot loader if this pin is asserted at boot time.
+        value:
+        restrictions:
+            - '$notnull'
+
+    BOOT_SERIAL_DETECT_PIN_CFG:
+        description: >
+            GPIO configuration for the serial boot loader detect pin.
+        value: 'HAL_GPIO_PULL_UP'
+
+    BOOT_SERIAL_DETECT_PIN_VAL:
+        description: >
+            The value the detect pin must be set to for the serial boot loader
+            to start.
+        value: 0
+
+    BOOT_SERIAL_REPORT_PIN:
+        description: >
+            The GPIO to toggle while the serial boot loader is running.  Set to
+            -1 to disable reporting.
+        value: 'LED_BLINK_PIN'
+
+    BOOT_SERIAL_REPORT_FREQ:
+        description: >
+            The toggle rate, in Hz, of the serial boot loader report pin.
+        value: 4
diff --git a/boot/boot_serial/test/pkg.yml b/boot/boot_serial/test/pkg.yml
index 26c160c..993272b 100644
--- a/boot/boot_serial/test/pkg.yml
+++ b/boot/boot_serial/test/pkg.yml
@@ -23,7 +23,7 @@
 pkg.keywords:
 
 pkg.deps:
-    - boot/boot_serial
+    - "@mcuboot/boot/boot_serial"
     - test/testutil
 
 pkg.deps.SELFTEST:
diff --git a/boot/mynewt/pkg.yml b/boot/mynewt/pkg.yml
index 1d563b8..b81966b 100644
--- a/boot/mynewt/pkg.yml
+++ b/boot/mynewt/pkg.yml
@@ -25,12 +25,14 @@
 pkg.keywords:
     - loader
 
+pkg.cflags:
+    - "-DMCUBOOT_MYNEWT"
+
 pkg.deps:
     - "@mcuboot/boot/mynewt/mcuboot_config"
     - "@mcuboot/boot/bootutil"
     - "@apache-mynewt-core/kernel/os"
-    - "@apache-mynewt-core/sys/console/stub"
+    - "@apache-mynewt-core/sys/console/minimal"
 
 pkg.deps.BOOT_SERIAL.OVERWRITE:
-    - "@apache-mynewt-core/sys/console/full"
     - "@mcuboot/boot/boot_serial"
diff --git a/boot/mynewt/src/main.c b/boot/mynewt/src/main.c
index 9971c9f..3033d07 100755
--- a/boot/mynewt/src/main.c
+++ b/boot/mynewt/src/main.c
@@ -17,6 +17,10 @@
  * under the License.
  */
 
+#ifdef MCUBOOT_MYNEWT
+#include "mcuboot_config/mcuboot_config.h"
+#endif
+
 #include <assert.h>
 #include <stddef.h>
 #include <inttypes.h>
@@ -74,8 +78,15 @@
      * Configure a GPIO as input, and compare it against expected value.
      * If it matches, await for download commands from serial.
      */
+#ifdef MCUBOOT_MYNEWT
+    hal_gpio_init_in(MYNEWT_VAL(BOOT_SERIAL_DETECT_PIN),
+                     MYNEWT_VAL(BOOT_SERIAL_DETECT_PIN_CFG));
+    if (hal_gpio_read(MYNEWT_VAL(BOOT_SERIAL_DETECT_PIN)) ==
+                      MYNEWT_VAL(BOOT_SERIAL_DETECT_PIN_VAL)) {
+#else
     hal_gpio_init_in(BOOT_SERIAL_DETECT_PIN, BOOT_SERIAL_DETECT_PIN_CFG);
     if (hal_gpio_read(BOOT_SERIAL_DETECT_PIN) == BOOT_SERIAL_DETECT_PIN_VAL) {
+#endif
         boot_serial_start(BOOT_SER_CONS_INPUT);
         assert(0);
     }
diff --git a/boot/mynewt/syscfg.yml b/boot/mynewt/syscfg.yml
index 0ab9a14..778ba5f 100644
--- a/boot/mynewt/syscfg.yml
+++ b/boot/mynewt/syscfg.yml
@@ -30,3 +30,4 @@
     SYSINIT_CONSTRAIN_INIT: 0
     OS_SCHEDULING: 0
     OS_CPUTIME_TIMER_NUM: -1
+    CONSOLE_COMPAT: 1