http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/arduino_primo_nrf52/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/arduino_primo_nrf52/pkg.yml 
b/hw/bsp/arduino_primo_nrf52/pkg.yml
index c49bc24..63fe461 100644
--- a/hw/bsp/arduino_primo_nrf52/pkg.yml
+++ b/hw/bsp/arduino_primo_nrf52/pkg.yml
@@ -33,12 +33,63 @@ pkg.linkerscript: "primo.ld"
 pkg.linkerscript.bootloader.OVERWRITE: "boot-primo.ld"
 pkg.downloadscript: primo_download.sh
 pkg.debugscript: primo_debug.sh
-pkg.cflags: -DNRF52 -DSPI_MASTER_0_ENABLE
+pkg.cflags:
+    # Nordic SDK files require these defines.
+    - '-DNRF52'
+    - '-DSPI_MASTER_0_ENABLE'
+
 pkg.deps:
-    - hw/mcu/nordic
     - hw/mcu/nordic/nrf52xxx
     - libs/baselibc
-    - drivers/uart/uart_hal
-    - drivers/uart/uart_bitbang
+
 pkg.deps.BLE_DEVICE:
     - net/nimble/drivers/nrf52
+
+pkg.deps.ADC_0:
+    - drivers/adc/adc_nrf52
+
+pkg.deps.UART_0:
+    - drivers/uart/uart_hal
+
+pkg.deps.UART_1:
+    - drivers/uart/uart_bitbang
+
+pkg.syscfg_defs:
+    BSP_NRF52:
+        description: 'TBD'
+        value: 1
+
+    CLOCK_FREQ:
+        description: 'TBD'
+        value:  1000000
+
+    XTAL_32768:
+        description: 'TBD'
+        value: 1
+
+    ADC_0:
+        description: 'TBD'
+        value:  1
+    ADC_0_RESOLUTION:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_RESOLUTION'
+    ADC_0_OVERSAMPLE:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_OVERSAMPLE'
+    ADC_0_INTERRUPT_PRIORITY:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_IRQ_PRIORITY'
+
+    UART_0:
+        description: 'TBD'
+        value:  1
+    UART_1:
+        description: 'TBD'
+        value:  0
+
+    SPI_MASTER:
+        description: 'TBD'
+        value:  1
+    SPI_SLAVE:
+        description: 'TBD'
+        value:  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/bmd300eval/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/pkg.yml b/hw/bsp/bmd300eval/pkg.yml
index 5cc570d..0035ce2 100644
--- a/hw/bsp/bmd300eval/pkg.yml
+++ b/hw/bsp/bmd300eval/pkg.yml
@@ -32,10 +32,63 @@ pkg.linkerscript: "bmd300eval.ld"
 pkg.linkerscript.bootloader.OVERWRITE: "boot-bmd300eval.ld"
 pkg.downloadscript: bmd300eval_download.sh
 pkg.debugscript: bmd300eval_debug.sh
-pkg.cflags: -DNRF52 -DBSP_HAS_32768_XTAL -DSPI_MASTER_0_ENABLE
+pkg.cflags:
+    # Nordic SDK files require these defines.
+    - '-DNRF52'
+    - '-DSPI_MASTER_0_ENABLE'
+
 pkg.deps:
-    - hw/mcu/nordic
     - hw/mcu/nordic/nrf52xxx
     - libs/baselibc
+
 pkg.deps.BLE_DEVICE:
     - net/nimble/drivers/nrf52
+
+pkg.deps.ADC_0:
+    - drivers/adc/adc_nrf52
+
+pkg.deps.UART_0:
+    - drivers/uart/uart_hal
+
+pkg.deps.UART_1:
+    - drivers/uart/uart_bitbang
+
+pkg.syscfg_defs:
+    BSP_NRF52:
+        description: 'TBD'
+        value: 1
+
+    CLOCK_FREQ:
+        description: 'TBD'
+        value:  1000000
+
+    XTAL_32768:
+        description: 'TBD'
+        value: 1
+
+    ADC_0:
+        description: 'TBD'
+        value:  1
+    ADC_0_RESOLUTION:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_RESOLUTION'
+    ADC_0_OVERSAMPLE:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_OVERSAMPLE'
+    ADC_0_INTERRUPT_PRIORITY:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_IRQ_PRIORITY'
+
+    UART_0:
+        description: 'TBD'
+        value:  1
+    UART_1:
+        description: 'TBD'
+        value:  0
+
+    SPI_MASTER:
+        description: 'TBD'
+        value:  1
+    SPI_SLAVE:
+        description: 'TBD'
+        value:  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/native/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/native/pkg.yml b/hw/bsp/native/pkg.yml
index 0de14d6..ede1525 100644
--- a/hw/bsp/native/pkg.yml
+++ b/hw/bsp/native/pkg.yml
@@ -25,11 +25,12 @@ pkg.homepage: "http://mynewt.apache.org/";
 pkg.keywords:
     - native
     - bsp
+pkg.debugscript: "native_debug.sh"
 
 pkg.arch: sim
 pkg.compiler: compiler/sim
 pkg.deps:
     - hw/mcu/native
+
 pkg.deps.BLE_DEVICE:
     - net/nimble/drivers/native
-pkg.debugscript: "native_debug.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/native/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/native/src/hal_bsp.c b/hw/bsp/native/src/hal_bsp.c
index dadee14..d65ac11 100644
--- a/hw/bsp/native/src/hal_bsp.c
+++ b/hw/bsp/native/src/hal_bsp.c
@@ -23,7 +23,6 @@
 #include <inttypes.h>
 #include "hal/hal_flash_int.h"
 #include "mcu/native_bsp.h"
-#include "hal/hal_adc_int.h"
 #include "bsp/bsp_sysid.h"
 #include "mcu/mcu_hal.h"
 #include <bsp/bsp.h>
@@ -31,7 +30,6 @@
 #include <mcu/hal_pwm.h>
 #include <mcu/hal_dac.h>
 
-
 const struct hal_flash *
 bsp_flash_dev(uint8_t id)
 {
@@ -43,76 +41,3 @@ bsp_flash_dev(uint8_t id)
     }
     return &native_flash_dev;
 }
-
-/* This is the factory that creates adc devices for the application.
- * Based on the system ID defined, this maps to a creation function for
- * the specific underlying driver */
-extern struct hal_adc *
-bsp_get_hal_adc(enum system_device_id sysid) 
-{    
-    switch(sysid) {
-        case NATIVE_A0:
-            return native_adc_random_create(MCU_ADC_CHANNEL_0);
-        case NATIVE_A1:
-            return native_adc_random_create(MCU_ADC_CHANNEL_1);
-        case NATIVE_A2:
-            return native_adc_mmm_create(MCU_ADC_CHANNEL_2);
-        case NATIVE_A3:
-            return native_adc_mmm_create(MCU_ADC_CHANNEL_3);
-        case NATIVE_A4:
-            return native_adc_mmm_create(MCU_ADC_CHANNEL_4);
-        case NATIVE_A5:        
-            /* for this BSP we hard code the name of the ADC sample file */
-            return native_adc_file_create(MCU_ADC_CHANNEL_5, "foo.txt");
-        default:
-            break;
-    }
-    return NULL;
-}
-
-struct hal_pwm *
-bsp_get_hal_pwm_driver(enum system_device_id sysid) 
-{
-    switch(sysid) 
-    {
-        case NATIVE_BSP_PWM_0:
-            return native_pwm_create (NATIVE_MCU_PWM0);
-        case NATIVE_BSP_PWM_1:
-            return native_pwm_create (NATIVE_MCU_PWM1);
-        case NATIVE_BSP_PWM_2:
-            return native_pwm_create (NATIVE_MCU_PWM2);
-        case NATIVE_BSP_PWM_3:
-            return native_pwm_create (NATIVE_MCU_PWM3);
-        case NATIVE_BSP_PWM_4:
-            return native_pwm_create (NATIVE_MCU_PWM4);
-        case NATIVE_BSP_PWM_5:
-            return native_pwm_create (NATIVE_MCU_PWM5);
-        case NATIVE_BSP_PWM_6:
-            return native_pwm_create (NATIVE_MCU_PWM6);
-        case NATIVE_BSP_PWM_7:
-            return native_pwm_create (NATIVE_MCU_PWM7);
-        default:
-            break;
-    }
-    return NULL;
-}
-
-
-struct hal_dac *
-bsp_get_hal_dac(enum system_device_id sysid) 
-{
-    switch(sysid) 
-    {
-        case NATIVE_BSP_DAC_0:
-            return native_dac_create(NATIVE_MCU_DAC0);
-        case NATIVE_BSP_DAC_1:
-            return native_dac_create(NATIVE_MCU_DAC1);
-        case NATIVE_BSP_DAC_2:
-            return native_dac_create(NATIVE_MCU_DAC2);
-        case NATIVE_BSP_DAC_3:
-            return native_dac_create(NATIVE_MCU_DAC3);
-        default:
-            break;
-    }
-    return NULL;   
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/nrf51-arduino_101/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/pkg.yml b/hw/bsp/nrf51-arduino_101/pkg.yml
index ee29287..05ff47a 100644
--- a/hw/bsp/nrf51-arduino_101/pkg.yml
+++ b/hw/bsp/nrf51-arduino_101/pkg.yml
@@ -32,9 +32,62 @@ pkg.linkerscript: "nrf51-arduino_101.ld"
 pkg.linkerscript.bootloader.OVERWRITE: "boot-nrf51-arduino_101.ld"
 pkg.downloadscript: nrf51dk-16kbram_download.sh
 pkg.debugscript: nrf51dk-16kbram_debug.sh
-pkg.cflags: -DNRF51
+pkg.cflags:
+    # Nordic SDK files require these defines.
+    - '-DNRF52'
+
 pkg.deps:
     - hw/mcu/nordic/nrf51xxx
     - libs/baselibc
+
 pkg.deps.BLE_DEVICE:
     - net/nimble/drivers/nrf51
+
+pkg.deps.ADC_0:
+    - drivers/adc/adc_nrf51
+
+pkg.deps.UART_0:
+    - drivers/uart/uart_hal
+
+pkg.deps.UART_1:
+    - drivers/uart/uart_bitbang
+
+pkg.syscfg_defs:
+    BSP_NRF51:
+        description: 'TBD'
+        value: 1
+
+    CLOCK_FREQ:
+        description: 'TBD'
+        value:  1000000
+
+    XTAL_32768:
+        description: 'TBD'
+        value: 1
+
+    ADC_0:
+        description: 'TBD'
+        value:  1
+    ADC_0_RESOLUTION:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_RESOLUTION'
+    ADC_0_OVERSAMPLE:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_OVERSAMPLE'
+    ADC_0_INTERRUPT_PRIORITY:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_IRQ_PRIORITY'
+
+    UART_0:
+        description: 'TBD'
+        value:  1
+    UART_1:
+        description: 'TBD'
+        value:  0
+
+    SPI_MASTER:
+        description: 'TBD'
+        value:  1
+    SPI_SLAVE:
+        description: 'TBD'
+        value:  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/nrf51-blenano/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/pkg.yml b/hw/bsp/nrf51-blenano/pkg.yml
index ea41d92..20cd656 100644
--- a/hw/bsp/nrf51-blenano/pkg.yml
+++ b/hw/bsp/nrf51-blenano/pkg.yml
@@ -33,9 +33,62 @@ pkg.linkerscript: "nrf51dk.ld"
 pkg.linkerscript.bootloader.OVERWRITE: "boot-nrf51dk.ld"
 pkg.downloadscript: nrf51dk_download.sh
 pkg.debugscript: nrf51dk_debug.sh
-pkg.cflags: -DNRF51
+pkg.cflags:
+    # Nordic SDK files require these defines.
+    - '-DNRF52'
+
 pkg.deps:
     - hw/mcu/nordic/nrf51xxx
     - libs/baselibc
+
 pkg.deps.BLE_DEVICE:
     - net/nimble/drivers/nrf51
+
+pkg.deps.ADC_0:
+    - drivers/adc/adc_nrf51
+
+pkg.deps.UART_0:
+    - drivers/uart/uart_hal
+
+pkg.deps.UART_1:
+    - drivers/uart/uart_bitbang
+
+pkg.syscfg_defs:
+    BSP_NRF51:
+        description: 'TBD'
+        value: 1
+
+    CLOCK_FREQ:
+        description: 'TBD'
+        value:  1000000
+
+    XTAL_32768:
+        description: 'TBD'
+        value: 1
+
+    ADC_0:
+        description: 'TBD'
+        value:  1
+    ADC_0_RESOLUTION:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_RESOLUTION'
+    ADC_0_OVERSAMPLE:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_OVERSAMPLE'
+    ADC_0_INTERRUPT_PRIORITY:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_IRQ_PRIORITY'
+
+    UART_0:
+        description: 'TBD'
+        value:  1
+    UART_1:
+        description: 'TBD'
+        value:  0
+
+    SPI_MASTER:
+        description: 'TBD'
+        value:  1
+    SPI_SLAVE:
+        description: 'TBD'
+        value:  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/nrf51dk-16kbram/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/pkg.yml b/hw/bsp/nrf51dk-16kbram/pkg.yml
index 5273846..c9c11d2 100644
--- a/hw/bsp/nrf51dk-16kbram/pkg.yml
+++ b/hw/bsp/nrf51dk-16kbram/pkg.yml
@@ -32,10 +32,62 @@ pkg.linkerscript: "nrf51dk-16kbram.ld"
 pkg.linkerscript.bootloader.OVERWRITE: "boot-nrf51dk-16kbram.ld"
 pkg.downloadscript: nrf51dk-16kbram_download.sh
 pkg.debugscript: nrf51dk-16kbram_debug.sh
-pkg.cflags: -DNRF51
+pkg.cflags:
+    # Nordic SDK files require these defines.
+    - '-DNRF52'
+
 pkg.deps:
     - hw/mcu/nordic/nrf51xxx
     - libs/baselibc
-    - drivers/uart/uart_hal
+
 pkg.deps.BLE_DEVICE:
     - net/nimble/drivers/nrf51
+
+pkg.deps.ADC_0:
+    - drivers/adc/adc_nrf51
+
+pkg.deps.UART_0:
+    - drivers/uart/uart_hal
+
+pkg.deps.UART_1:
+    - drivers/uart/uart_bitbang
+
+pkg.syscfg_defs:
+    BSP_NRF51:
+        description: 'TBD'
+        value: 1
+
+    CLOCK_FREQ:
+        description: 'TBD'
+        value:  1000000
+
+    XTAL_32768:
+        description: 'TBD'
+        value: 1
+
+    ADC_0:
+        description: 'TBD'
+        value:  1
+    ADC_0_RESOLUTION:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_RESOLUTION'
+    ADC_0_OVERSAMPLE:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_OVERSAMPLE'
+    ADC_0_INTERRUPT_PRIORITY:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_IRQ_PRIORITY'
+
+    UART_0:
+        description: 'TBD'
+        value:  1
+    UART_1:
+        description: 'TBD'
+        value:  0
+
+    SPI_MASTER:
+        description: 'TBD'
+        value:  1
+    SPI_SLAVE:
+        description: 'TBD'
+        value:  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/nrf51dk/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/pkg.yml b/hw/bsp/nrf51dk/pkg.yml
index 6b3705d..c6d66bc 100644
--- a/hw/bsp/nrf51dk/pkg.yml
+++ b/hw/bsp/nrf51dk/pkg.yml
@@ -32,12 +32,56 @@ pkg.linkerscript: "nrf51dk.ld"
 pkg.linkerscript.bootloader.OVERWRITE: "boot-nrf51dk.ld"
 pkg.downloadscript: nrf51dk_download.sh
 pkg.debugscript: nrf51dk_debug.sh
-pkg.cflags: -DNRF51 -DBSP_HAS_32768_XTAL
+pkg.cflags:
+    # Nordic SDK files require this define.
+    - '-DNRF51'
+
 pkg.deps:
     - hw/mcu/nordic/nrf51xxx
     - libs/baselibc
-    - drivers/uart/uart_hal
+
 pkg.deps.BLE_DEVICE:
     - net/nimble/drivers/nrf51
-pkg.features:
-    - ADC_NRF51
+
+pkg.deps.ADC_0:
+    - drivers/adc/adc_nrf51
+
+pkg.deps.UART_0:
+    - drivers/uart/uart_hal
+
+pkg.syscfg_defs:
+    BSP_NRF51:
+        description: 'TBD'
+        value: 1
+
+    CLOCK_FREQ:
+        description: 'TBD'
+        value: 1000000
+
+    32768_XTAL:
+        description: 'TBD'
+        value: 1
+
+    ADC_0:
+        description: 'TBD'
+        value:  1
+    ADC_0_RESOLUTION:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_RESOLUTION'
+    ADC_0_OVERSAMPLE:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_OVERSAMPLE'
+    ADC_0_INTERRUPT_PRIORITY:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_IRQ_PRIORITY'
+
+    UART_0:
+        description: 'TBD'
+        value:  1
+
+    SPI_MASTER:
+        description: 'TBD'
+        value:  1
+    SPI_SLAVE:
+        description: 'TBD'
+        value:  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/nrf52dk/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/pkg.yml b/hw/bsp/nrf52dk/pkg.yml
index 41b4222..5e617e5 100644
--- a/hw/bsp/nrf52dk/pkg.yml
+++ b/hw/bsp/nrf52dk/pkg.yml
@@ -32,13 +32,63 @@ pkg.linkerscript: "nrf52dk.ld"
 pkg.linkerscript.bootloader.OVERWRITE: "boot-nrf52dk.ld"
 pkg.downloadscript: nrf52dk_download.sh
 pkg.debugscript: nrf52dk_debug.sh
-pkg.cflags: -DNRF52 -DBSP_HAS_32768_XTAL -DSPI_MASTER_0_ENABLE
+pkg.cflags:
+    # Nordic SDK files require these defines.
+    - '-DNRF52'
+    - '-DSPI_MASTER_0_ENABLE'
+
 pkg.deps:
-    - hw/mcu/nordic
     - hw/mcu/nordic/nrf52xxx
     - libs/baselibc
-    - drivers/uart/uart_hal
+
 pkg.deps.BLE_DEVICE:
     - net/nimble/drivers/nrf52
-pkg.features:
-    - ADC_NRF52
+
+pkg.deps.ADC_0:
+    - drivers/adc/adc_nrf52
+
+pkg.deps.UART_0:
+    - drivers/uart/uart_hal
+
+pkg.deps.UART_1:
+    - drivers/uart/uart_bitbang
+
+pkg.syscfg_defs:
+    BSP_NRF52:
+        description: 'TBD'
+        value: 1
+
+    CLOCK_FREQ:
+        description: 'TBD'
+        value:  1000000
+
+    XTAL_32768:
+        description: 'TBD'
+        value: 1
+
+    ADC_0:
+        description: 'TBD'
+        value:  1
+    ADC_0_RESOLUTION:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_RESOLUTION'
+    ADC_0_OVERSAMPLE:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_OVERSAMPLE'
+    ADC_0_INTERRUPT_PRIORITY:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_IRQ_PRIORITY'
+
+    UART_0:
+        description: 'TBD'
+        value:  1
+    UART_1:
+        description: 'TBD'
+        value:  0
+
+    SPI_MASTER:
+        description: 'TBD'
+        value:  1
+    SPI_SLAVE:
+        description: 'TBD'
+        value:  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/nrf52dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/os_bsp.c b/hw/bsp/nrf52dk/src/os_bsp.c
index 0a521af..1b3cfdd 100644
--- a/hw/bsp/nrf52dk/src/os_bsp.c
+++ b/hw/bsp/nrf52dk/src/os_bsp.c
@@ -16,25 +16,32 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 #include <assert.h>
-#include <hal/flash_map.h>
-#include <hal/hal_bsp.h>
-#include <hal/hal_cputime.h>
-#include <mcu/nrf52_hal.h>
 
-#include <os/os_dev.h>
+#include "syscfg/syscfg.h"
+#include "hal/flash_map.h"
+#include "hal/hal_bsp.h"
+#include "hal/hal_cputime.h"
+#include "hal/hal_flash.h"
+#include "hal/hal_spi.h"
+#include "mcu/nrf52_hal.h"
+#include "uart/uart.h"
+#include "uart_hal/uart_hal.h"
+#include "os/os_dev.h"
 
-#include <uart/uart.h>
-#include <uart_hal/uart_hal.h>
-#include <hal/hal_spi.h>
-#ifdef BSP_CFG_SPI_MASTER
+#if MYNEWT_VAL(SPI_MASTER)
 #include "nrf_drv_spi.h"
 #endif
-#ifdef BSP_CFG_SPI_SLAVE
+#if MYNEWT_VAL(SPI_SLAVE)
 #include "nrf_drv_spis.h"
 #endif
 #include "nrf_drv_config.h"
-#include <app_util_platform.h>
+#include "app_util_platform.h"
+#include "nrf.h"
+#include "app_error.h"
+#include "adc_nrf52/adc_nrf52.h"
+#include "nrf_drv_saadc.h"
 
 static struct flash_area bsp_flash_areas[] = {
     [FLASH_AREA_BOOTLOADER] = {
@@ -64,9 +71,21 @@ static struct flash_area bsp_flash_areas[] = {
         .fa_size = (12 * 1024)
     }
 };
-static struct uart_dev hal_uart0;
 
-void _close(int fd);
+#if MYNEWT_VAL(UART_0)
+static struct uart_dev os_bsp_uart0;
+#endif
+
+#if MYNEWT_VAL(ADC_0)
+static struct adc_dev os_bsp_adc0;
+static nrf_drv_saadc_config_t os_bsp_adc0_config = {
+    .resolution         = MYNEWT_VAL(ADC_0_RESOLUTION),
+    .oversample         = MYNEWT_VAL(ADC_0_OVERSAMPLE),
+    .interrupt_priority = MYNEWT_VAL(ADC_0_INTERRUPT_PRIORITY),
+};
+#endif
+
+//void _close(int fd);
 
 /*
  * Returns the flash map slot where the currently active image is located.
@@ -86,36 +105,53 @@ void
 bsp_init(void)
 {
     int rc;
-#ifdef BSP_CFG_SPI_MASTER
+
+#if MYNEWT_VAL(SPI_MASTER)
     nrf_drv_spi_config_t spi_cfg = NRF_DRV_SPI_DEFAULT_CONFIG(0);
 #endif
-#ifdef BSP_CFG_SPI_SLAVE
+#if MYNEWT_VAL(SPI_SLAVE)
     nrf_drv_spis_config_t spi_cfg = NRF_DRV_SPIS_DEFAULT_CONFIG(0);
 #endif
 
     /*
      * XXX this reference is here to keep this function in.
      */
-    _sbrk(0);
-    _close(0);
+    (void)_sbrk;
+    //(void)_close;
+
+    /* Set cputime to count at 1 usec increments */
+    rc = cputime_init(MYNEWT_VAL(CLOCK_FREQ));
+    assert(rc == 0);
 
     flash_area_init(bsp_flash_areas,
       sizeof(bsp_flash_areas) / sizeof(bsp_flash_areas[0]));
 
-    rc = os_dev_create((struct os_dev *) &hal_uart0, "uart0",
-      OS_DEV_INIT_PRIMARY, 0, uart_hal_init, (void *)bsp_uart_config());
+    rc = hal_flash_init();
     assert(rc == 0);
 
-#ifdef BSP_CFG_SPI_MASTER
+#if MYNEWT_VAL(SPI_MASTER)
     /*  We initialize one SPI interface as a master. */
     rc = hal_spi_init(0, &spi_cfg, HAL_SPI_TYPE_MASTER);
     assert(rc == 0);
 #endif
 
-#ifdef BSP_CFG_SPI_SLAVE
+#if MYNEWT_VAL(SPI_SLAVE)
     /*  We initialize one SPI interface as a master. */
     spi_cfg.csn_pin = SPIS0_CONFIG_CSN_PIN;
     rc = hal_spi_init(0, &spi_cfg, HAL_SPI_TYPE_SLAVE);
     assert(rc == 0);
 #endif
+
+#if MYNEWT_VAL(UART_0)
+    rc = os_dev_create((struct os_dev *) &os_bsp_uart0, "uart0",
+      OS_DEV_INIT_PRIMARY, 0, uart_hal_init, (void *)bsp_uart_config());
+    assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(ADC_0)
+    rc = os_dev_create((struct os_dev *) &os_bsp_adc0, "adc0",
+            OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
+            nrf52_adc_dev_init, &os_bsp_adc0_config);
+    assert(rc == 0);
+#endif
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/nrf52pdk/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/pkg.yml b/hw/bsp/nrf52pdk/pkg.yml
index 6bc7ef4..d57f7e2 100644
--- a/hw/bsp/nrf52pdk/pkg.yml
+++ b/hw/bsp/nrf52pdk/pkg.yml
@@ -32,11 +32,63 @@ pkg.linkerscript: "nrf52pdk.ld"
 pkg.linkerscript.bootloader.OVERWRITE: "boot-nrf52pdk.ld"
 pkg.downloadscript: nrf52pdk_download.sh
 pkg.debugscript: nrf52pdk_debug.sh
-pkg.cflags: -DNRF52 -DSPI_MASTER_0_ENABLE
+pkg.cflags:
+    # Nordic SDK files require these defines.
+    - '-DNRF52'
+    - '-DSPI_MASTER_0_ENABLE'
+
 pkg.deps:
-    - hw/mcu/nordic
     - hw/mcu/nordic/nrf52xxx
     - libs/baselibc
-    - drivers/uart/uart_hal
+
 pkg.deps.BLE_DEVICE:
     - net/nimble/drivers/nrf52
+
+pkg.deps.ADC_0:
+    - drivers/adc/adc_nrf52
+
+pkg.deps.UART_0:
+    - drivers/uart/uart_hal
+
+pkg.deps.UART_1:
+    - drivers/uart/uart_bitbang
+
+pkg.syscfg_defs:
+    BSP_NRF52:
+        description: 'TBD'
+        value: 1
+
+    CLOCK_FREQ:
+        description: 'TBD'
+        value:  1000000
+
+    XTAL_32768:
+        description: 'TBD'
+        value: 0
+
+    ADC_0:
+        description: 'TBD'
+        value:  0
+    ADC_0_RESOLUTION:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_RESOLUTION'
+    ADC_0_OVERSAMPLE:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_OVERSAMPLE'
+    ADC_0_INTERRUPT_PRIORITY:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_IRQ_PRIORITY'
+
+    UART_0:
+        description: 'TBD'
+        value:  1
+    UART_1:
+        description: 'TBD'
+        value:  0
+
+    SPI_MASTER:
+        description: 'TBD'
+        value:  0
+    SPI_SLAVE:
+        description: 'TBD'
+        value:  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/bsp/olimex_stm32-e407_devboard/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/pkg.yml 
b/hw/bsp/olimex_stm32-e407_devboard/pkg.yml
index 761d9ba..3b23131 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/pkg.yml
+++ b/hw/bsp/olimex_stm32-e407_devboard/pkg.yml
@@ -33,8 +33,51 @@ pkg.linkerscript: "olimex_stm32-e407_devboard.ld"
 pkg.linkerscript.bootloader.OVERWRITE: "boot-olimex_stm32-e407_devboard.ld"
 pkg.downloadscript: "olimex_stm32-e407_devboard_download.sh"
 pkg.debugscript: "olimex_stm32-e407_devboard_debug.sh"
-pkg.cflags: -DSTM32F407xx
+pkg.cflags:
+    # STM SDK files require these defines.
+    - '-DSTM32F407xx'
+
 pkg.deps:
     - hw/mcu/stm/stm32f4xx
     - libs/baselibc
+
+pkg.deps.ADC_0:
+    - drivers/adc/adc_nrf52
+
+pkg.deps.UART_0:
     - drivers/uart/uart_hal
+
+pkg.deps.UART_1:
+    - drivers/uart/uart_bitbang
+
+pkg.syscfg_defs:
+    CLOCK_FREQ:
+        description: 'TBD'
+        value:  1000000
+
+    ADC_0:
+        description: 'TBD'
+        value:  1
+    ADC_0_RESOLUTION:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_RESOLUTION'
+    ADC_0_OVERSAMPLE:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_OVERSAMPLE'
+    ADC_0_INTERRUPT_PRIORITY:
+        description: 'TBD'
+        value: 'SAADC_CONFIG_IRQ_PRIORITY'
+
+    UART_0:
+        description: 'TBD'
+        value:  1
+    UART_1:
+        description: 'TBD'
+        value:  0
+
+    SPI_MASTER:
+        description: 'TBD'
+        value:  1
+    SPI_SLAVE:
+        description: 'TBD'
+        value:  0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/hal/include/hal/flash_map.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/flash_map.h b/hw/hal/include/hal/flash_map.h
index 1bf07ee..a073078 100644
--- a/hw/hal/include/hal/flash_map.h
+++ b/hw/hal/include/hal/flash_map.h
@@ -61,6 +61,9 @@ struct flash_area {
 #define FLASH_AREA_CORE                 2
 #define FLASH_AREA_REBOOT_LOG           5
 
+extern const struct flash_area *flash_map;
+extern int flash_map_entries;
+
 /*
  * Initializes flash map. Memory will be referenced by flash_map code
  * from this on.
@@ -97,7 +100,7 @@ int flash_area_to_sectors(int idx, int *cnt, struct 
flash_area *ret);
  * Given flash map index, return sector info in NFFS area desc format.
  */
 struct nffs_area_desc;
-int flash_area_to_nffs_desc(int idx, int *cnt, struct nffs_area_desc *nad);
+int nffs_misc_desc_from_flash_area(int idx, int *cnt, struct nffs_area_desc 
*nad);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/hal/include/hal/hal_bsp.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_bsp.h b/hw/hal/include/hal/hal_bsp.h
index 8ca8a69..c5d0ba1 100644
--- a/hw/hal/include/hal/hal_bsp.h
+++ b/hw/hal/include/hal/hal_bsp.h
@@ -29,6 +29,7 @@ extern "C" {
 /*
  * Initializes BSP; registers flash_map with the system.
  */
+void bsp_init_devs(void);
 void bsp_init(void);
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/hal/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/hal/pkg.yml b/hw/hal/pkg.yml
index f350040..2049849 100644
--- a/hw/hal/pkg.yml
+++ b/hw/hal/pkg.yml
@@ -24,6 +24,3 @@ pkg.homepage: "http://mynewt.apache.org/";
 pkg.keywords:
 
 pkg.deps: libs/os
-pkg.deps.NFFS:
-    - fs/nffs
-pkg.cflags.NFFS: -DNFFS_PRESENT

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/hal/src/flash_map.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/flash_map.c b/hw/hal/src/flash_map.c
index 4b06c29..d66b0ad 100644
--- a/hw/hal/src/flash_map.c
+++ b/hw/hal/src/flash_map.c
@@ -19,16 +19,14 @@
 #include <inttypes.h>
 #include <string.h>
 
+#include "syscfg/syscfg.h"
 #include "hal/hal_bsp.h"
 #include "hal/hal_flash.h"
 #include "hal/hal_flash_int.h"
-#ifdef NFFS_PRESENT
-#include <nffs/nffs.h>
-#endif
 #include "hal/flash_map.h"
 
-static const struct flash_area *flash_map;
-static int flash_map_entries;
+const struct flash_area *flash_map;
+int flash_map_entries;
 
 void
 flash_area_init(const struct flash_area *map, int map_entries)
@@ -86,74 +84,6 @@ flash_area_to_sectors(int idx, int *cnt, struct flash_area 
*ret)
     return 0;
 }
 
-#ifdef NFFS_PRESENT
-/*
- * Turn flash region into a set of areas for NFFS use.
- *
- * Limit the number of regions we return to be less than *cnt.
- * If sector count within region exceeds that, collect multiple sectors
- * to a region.
- */
-int
-flash_area_to_nffs_desc(int idx, int *cnt, struct nffs_area_desc *nad)
-{
-    int i, j;
-    const struct hal_flash *hf;
-    const struct flash_area *fa;
-    int max_cnt, move_on;
-    int first_idx, last_idx;
-    uint32_t start, size;
-    uint32_t min_size;
-
-    if (!flash_map || idx >= flash_map_entries) {
-        return -1;
-    }
-    first_idx = last_idx = -1;
-    max_cnt = *cnt;
-    *cnt = 0;
-
-    fa = &flash_map[idx];
-
-    hf = bsp_flash_dev(fa->fa_flash_id);
-    for (i = 0; i < hf->hf_sector_cnt; i++) {
-        hf->hf_itf->hff_sector_info(i, &start, &size);
-        if (start >= fa->fa_off && start < fa->fa_off + fa->fa_size) {
-            if (first_idx == -1) {
-                first_idx = i;
-            }
-            last_idx = i;
-            *cnt = *cnt + 1;
-        }
-    }
-    if (*cnt > max_cnt) {
-        min_size = fa->fa_size / max_cnt;
-    } else {
-        min_size = 0;
-    }
-    *cnt = 0;
-
-    move_on = 1;
-    for (i = first_idx, j = 0; i < last_idx + 1; i++) {
-        hf->hf_itf->hff_sector_info(i, &start, &size);
-        if (move_on) {
-            nad[j].nad_flash_id = fa->fa_flash_id;
-            nad[j].nad_offset = start;
-            nad[j].nad_length = size;
-            *cnt = *cnt + 1;
-            move_on = 0;
-        } else {
-            nad[j].nad_length += size;
-        }
-        if (nad[j].nad_length >= min_size) {
-            j++;
-            move_on = 1;
-        }
-    }
-    nad[*cnt].nad_length = 0;
-    return 0;
-}
-#endif /* NFFS_PRESENT */
-
 int
 flash_area_read(const struct flash_area *fa, uint32_t off, void *dst,
   uint32_t len)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/hal/src/test/flash_map_test.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/test/flash_map_test.c b/hw/hal/src/test/flash_map_test.c
deleted file mode 100644
index 06e065d..0000000
--- a/hw/hal/src/test/flash_map_test.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/**
- * 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.
- */
-#include <stdio.h>
-#include <string.h>
-
-#include <os/os.h>
-#include <testutil/testutil.h>
-#include "hal/flash_map.h"
-#include "hal/hal_bsp.h"
-#include "hal/hal_flash.h"
-#include "hal/hal_flash_int.h"
-
-/*
- * Test flash_area_to_sectors()
- */
-TEST_CASE(flash_map_test_case_1)
-{
-    const struct flash_area *fa;
-    int areas_checked = 0;
-    int i, j, rc;
-    const struct hal_flash *hf;
-    struct flash_area my_secs[32];
-    int my_sec_cnt;
-    uint32_t end;
-
-    os_init();
-
-    for (i = 0; i < 8; i++) {
-        rc = flash_area_open(i, &fa);
-        if (rc) {
-            continue;
-        }
-
-        hf = bsp_flash_dev(fa->fa_flash_id);
-        TEST_ASSERT_FATAL(hf != NULL, "bsp_flash_dev");
-
-        rc = flash_area_to_sectors(i, &my_sec_cnt, my_secs);
-        TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed");
-
-        end = fa->fa_off;
-        for (j = 0; j < my_sec_cnt; j++) {
-            TEST_ASSERT_FATAL(end == my_secs[j].fa_off, "Non contiguous area");
-            TEST_ASSERT_FATAL(my_secs[j].fa_flash_id == fa->fa_flash_id,
-              "Sectors not in same flash?");
-            end = my_secs[j].fa_off + my_secs[j].fa_size;
-        }
-        if (my_sec_cnt) {
-            areas_checked++;
-            TEST_ASSERT_FATAL(my_secs[my_sec_cnt - 1].fa_off +
-              my_secs[my_sec_cnt - 1].fa_size == fa->fa_off + fa->fa_size,
-              "Last sector not in the end");
-        }
-    }
-    TEST_ASSERT_FATAL(areas_checked != 0, "No flash map areas to check!");
-}
-
-/*
- * Test flash_erase
- */
-TEST_CASE(flash_map_test_case_2)
-{
-    const struct flash_area *fa;
-    struct flash_area secs[32];
-    int sec_cnt;
-    int i;
-    int rc;
-    uint32_t off;
-    uint8_t wd[256];
-    uint8_t rd[256];
-
-    os_init();
-
-    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fa);
-    TEST_ASSERT_FATAL(rc == 0, "flash_area_open() fail");
-
-    rc = flash_area_to_sectors(FLASH_AREA_IMAGE_0, &sec_cnt, secs);
-    TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed");
-
-    /*
-     * First erase the area so it's ready for use.
-     */
-    for (i = 0; i < sec_cnt; i++) {
-        rc = hal_flash_erase_sector(secs[i].fa_flash_id, secs[i].fa_off);
-        TEST_ASSERT_FATAL(rc == 0, "hal_flash_erase_sector() failed");
-    }
-    TEST_ASSERT_FATAL(rc == 0, "read data != write data");
-
-    memset(wd, 0xa5, sizeof(wd));
-
-    /* write stuff to beginning of every sector */
-    off = 0;
-    for (i = 0; i < sec_cnt; i++) {
-        rc = flash_area_write(fa, off, wd, sizeof(wd));
-        TEST_ASSERT_FATAL(rc == 0, "flash_area_write() fail");
-
-        /* read it back via hal_flash_Read() */
-        rc = hal_flash_read(fa->fa_flash_id, fa->fa_off + off, rd, sizeof(rd));
-        TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
-
-        rc = memcmp(wd, rd, sizeof(wd));
-        TEST_ASSERT_FATAL(rc == 0, "read data != write data");
-
-        /* write stuff to end of area */
-        rc = hal_flash_write(fa->fa_flash_id,
-          fa->fa_off + off + secs[i].fa_size - sizeof(wd), wd, sizeof(wd));
-        TEST_ASSERT_FATAL(rc == 0, "hal_flash_write() fail");
-
-        /* and read it back */
-        memset(rd, 0, sizeof(rd));
-        rc = flash_area_read(fa, off + secs[i].fa_size - sizeof(rd),
-          rd, sizeof(rd));
-        TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
-
-        rc = memcmp(wd, rd, sizeof(rd));
-        TEST_ASSERT_FATAL(rc == 0, "read data != write data");
-
-        off += secs[i].fa_size;
-    }
-    /* erase it */
-    rc = flash_area_erase(fa, 0, fa->fa_size);
-    TEST_ASSERT_FATAL(rc == 0, "read data != write data");
-
-    /* should read back ff all throughout*/
-    memset(wd, 0xff, sizeof(wd));
-    for (off = 0; off < fa->fa_size; off += sizeof(rd)) {
-         rc = flash_area_read(fa, off, rd, sizeof(rd));
-         TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
-
-         rc = memcmp(wd, rd, sizeof(rd));
-         TEST_ASSERT_FATAL(rc == 0, "area not erased");
-    }
-}
-
-TEST_SUITE(flash_map_test_suite)
-{
-    flash_map_test_case_1();
-    flash_map_test_case_2();
-}
-
-#ifdef MYNEWT_SELFTEST
-
-int
-main(int argc, char **argv)
-{
-    tu_config.tc_print_results = 1;
-    tu_init();
-
-    flash_map_test_suite();
-
-    return tu_any_failed;
-}
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/hal/test/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/hal/test/pkg.yml b/hw/hal/test/pkg.yml
new file mode 100644
index 0000000..943c0b3
--- /dev/null
+++ b/hw/hal/test/pkg.yml
@@ -0,0 +1,30 @@
+# 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.
+#
+pkg.name: hw/hal/test
+pkg.type: unittest
+pkg.description: "HAL unit tests."
+pkg.author: "Apache Mynewt <d...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+
+pkg.deps:
+    - hw/hal
+    - libs/testutil
+
+pkg.deps.SELFTEST:
+    - libs/console/stub

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/hal/test/src/flash_map_test.c
----------------------------------------------------------------------
diff --git a/hw/hal/test/src/flash_map_test.c b/hw/hal/test/src/flash_map_test.c
new file mode 100644
index 0000000..71d1e45
--- /dev/null
+++ b/hw/hal/test/src/flash_map_test.c
@@ -0,0 +1,170 @@
+/**
+ * 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.
+ */
+#include <stdio.h>
+#include <string.h>
+
+#include "syscfg/syscfg.h"
+#include "os/os.h"
+#include "testutil/testutil.h"
+#include "hal/flash_map.h"
+#include "hal/hal_bsp.h"
+#include "hal/hal_flash.h"
+#include "hal/hal_flash_int.h"
+
+/*
+ * Test flash_area_to_sectors()
+ */
+TEST_CASE(flash_map_test_case_1)
+{
+    const struct flash_area *fa;
+    int areas_checked = 0;
+    int i, j, rc;
+    const struct hal_flash *hf;
+    struct flash_area my_secs[32];
+    int my_sec_cnt;
+    uint32_t end;
+
+    os_init();
+
+    for (i = 0; i < 8; i++) {
+        rc = flash_area_open(i, &fa);
+        if (rc) {
+            continue;
+        }
+
+        hf = bsp_flash_dev(fa->fa_flash_id);
+        TEST_ASSERT_FATAL(hf != NULL, "bsp_flash_dev");
+
+        rc = flash_area_to_sectors(i, &my_sec_cnt, my_secs);
+        TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed");
+
+        end = fa->fa_off;
+        for (j = 0; j < my_sec_cnt; j++) {
+            TEST_ASSERT_FATAL(end == my_secs[j].fa_off, "Non contiguous area");
+            TEST_ASSERT_FATAL(my_secs[j].fa_flash_id == fa->fa_flash_id,
+              "Sectors not in same flash?");
+            end = my_secs[j].fa_off + my_secs[j].fa_size;
+        }
+        if (my_sec_cnt) {
+            areas_checked++;
+            TEST_ASSERT_FATAL(my_secs[my_sec_cnt - 1].fa_off +
+              my_secs[my_sec_cnt - 1].fa_size == fa->fa_off + fa->fa_size,
+              "Last sector not in the end");
+        }
+    }
+    TEST_ASSERT_FATAL(areas_checked != 0, "No flash map areas to check!");
+}
+
+/*
+ * Test flash_erase
+ */
+TEST_CASE(flash_map_test_case_2)
+{
+    const struct flash_area *fa;
+    struct flash_area secs[32];
+    int sec_cnt;
+    int i;
+    int rc;
+    uint32_t off;
+    uint8_t wd[256];
+    uint8_t rd[256];
+
+    os_init();
+
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fa);
+    TEST_ASSERT_FATAL(rc == 0, "flash_area_open() fail");
+
+    rc = flash_area_to_sectors(FLASH_AREA_IMAGE_0, &sec_cnt, secs);
+    TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed");
+
+    /*
+     * First erase the area so it's ready for use.
+     */
+    for (i = 0; i < sec_cnt; i++) {
+        rc = hal_flash_erase_sector(secs[i].fa_flash_id, secs[i].fa_off);
+        TEST_ASSERT_FATAL(rc == 0, "hal_flash_erase_sector() failed");
+    }
+    TEST_ASSERT_FATAL(rc == 0, "read data != write data");
+
+    memset(wd, 0xa5, sizeof(wd));
+
+    /* write stuff to beginning of every sector */
+    off = 0;
+    for (i = 0; i < sec_cnt; i++) {
+        rc = flash_area_write(fa, off, wd, sizeof(wd));
+        TEST_ASSERT_FATAL(rc == 0, "flash_area_write() fail");
+
+        /* read it back via hal_flash_Read() */
+        rc = hal_flash_read(fa->fa_flash_id, fa->fa_off + off, rd, sizeof(rd));
+        TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
+
+        rc = memcmp(wd, rd, sizeof(wd));
+        TEST_ASSERT_FATAL(rc == 0, "read data != write data");
+
+        /* write stuff to end of area */
+        rc = hal_flash_write(fa->fa_flash_id,
+          fa->fa_off + off + secs[i].fa_size - sizeof(wd), wd, sizeof(wd));
+        TEST_ASSERT_FATAL(rc == 0, "hal_flash_write() fail");
+
+        /* and read it back */
+        memset(rd, 0, sizeof(rd));
+        rc = flash_area_read(fa, off + secs[i].fa_size - sizeof(rd),
+          rd, sizeof(rd));
+        TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
+
+        rc = memcmp(wd, rd, sizeof(rd));
+        TEST_ASSERT_FATAL(rc == 0, "read data != write data");
+
+        off += secs[i].fa_size;
+    }
+    /* erase it */
+    rc = flash_area_erase(fa, 0, fa->fa_size);
+    TEST_ASSERT_FATAL(rc == 0, "read data != write data");
+
+    /* should read back ff all throughout*/
+    memset(wd, 0xff, sizeof(wd));
+    for (off = 0; off < fa->fa_size; off += sizeof(rd)) {
+         rc = flash_area_read(fa, off, rd, sizeof(rd));
+         TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
+
+         rc = memcmp(wd, rd, sizeof(rd));
+         TEST_ASSERT_FATAL(rc == 0, "area not erased");
+    }
+}
+
+TEST_SUITE(flash_map_test_suite)
+{
+    flash_map_test_case_1();
+    flash_map_test_case_2();
+}
+
+#if MYNEWT_VAL(SELFTEST)
+
+int
+main(int argc, char **argv)
+{
+    tu_config.tc_print_results = 1;
+    tu_init();
+
+    flash_map_test_suite();
+
+    return tu_any_failed;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/mcu/native/include/mcu/mcu_hal.h
----------------------------------------------------------------------
diff --git a/hw/mcu/native/include/mcu/mcu_hal.h 
b/hw/mcu/native/include/mcu/mcu_hal.h
index e6163b9..aced4dc 100644
--- a/hw/mcu/native/include/mcu/mcu_hal.h
+++ b/hw/mcu/native/include/mcu/mcu_hal.h
@@ -26,8 +26,6 @@
 extern "C" {
 #endif
 
-#include <hal/hal_adc.h>
-    
 /* this is a native build and these pins are not real.  They are used only
  * for simulated HAL devices */
     

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/mcu/native/src/hal_adc.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_adc.c b/hw/mcu/native/src/hal_adc.c
index 9460740..f54acc7 100644
--- a/hw/mcu/native/src/hal_adc.c
+++ b/hw/mcu/native/src/hal_adc.c
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+#if 0
 #include <fcntl.h>
 #include <unistd.h>
 #include <inttypes.h>
@@ -23,7 +24,6 @@
 #include <hal/hal_adc.h>
 #include <hal/hal_adc_int.h>
 #include <mcu/mcu_hal.h>
-#if 1
 
 
 /* forwards for the const structure below */
@@ -236,4 +236,4 @@ native_adc_file_read(struct hal_adc *padc)
     return -1;    
 }
 
-#endif
\ No newline at end of file
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/mcu/native/src/hal_dac.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_dac.c b/hw/mcu/native/src/hal_dac.c
index 9f60879..d5055ce 100644
--- a/hw/mcu/native/src/hal_dac.c
+++ b/hw/mcu/native/src/hal_dac.c
@@ -1,3 +1,4 @@
+#if 0
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -111,3 +112,4 @@ native_dac_write(struct hal_dac *pdac, int val)
     }
     return -1;    
 }
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/mcu/native/src/hal_pwm.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_pwm.c b/hw/mcu/native/src/hal_pwm.c
index 5d0688b..032bcad 100644
--- a/hw/mcu/native/src/hal_pwm.c
+++ b/hw/mcu/native/src/hal_pwm.c
@@ -1,3 +1,4 @@
+#if 0
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -130,4 +131,4 @@ native_pwm_enable_duty(struct hal_pwm *ppwm, uint16_t 
fraction)
     }
     return -2;
 }
-
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/mcu/nordic/nrf51xxx/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/pkg.yml b/hw/mcu/nordic/nrf51xxx/pkg.yml
index 7ecb890..4485725 100644
--- a/hw/mcu/nordic/nrf51xxx/pkg.yml
+++ b/hw/mcu/nordic/nrf51xxx/pkg.yml
@@ -24,9 +24,6 @@ pkg.homepage: "http://mynewt.apache.org/";
 pkg.keywords:
     - nrf51
 
-pkg.features:
-    - NRF51
-
 pkg.deps: 
     - hw/hal 
     - libs/cmsis-core 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h 
b/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
index 138a931..09e9c93 100644
--- a/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
+++ b/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
@@ -20,9 +20,10 @@
 #ifndef __MCU_CORTEX_M4_H__
 #define __MCU_CORTEX_M4_H__
 
+#include "syscfg/syscfg.h"
 #include "nrf52.h"
 
-#if defined(BSP_HAS_32768_XTAL)
+#if MYNEWT_VAL(XTAL_32768)
 #define OS_TICKS_PER_SEC    (128)
 #else
 #define OS_TICKS_PER_SEC    (1000)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/mcu/nordic/nrf52xxx/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/pkg.yml b/hw/mcu/nordic/nrf52xxx/pkg.yml
index 707765e..27fdb70 100644
--- a/hw/mcu/nordic/nrf52xxx/pkg.yml
+++ b/hw/mcu/nordic/nrf52xxx/pkg.yml
@@ -24,9 +24,6 @@ pkg.homepage: "http://mynewt.apache.org/";
 pkg.keywords:
     - nrf52
 
-pkg.features:
-    - NRF52
-
 pkg.deps: 
     - hw/hal 
     - hw/mcu/nordic

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c 
b/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
index 2b5d58f..a96e13a 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
@@ -18,11 +18,12 @@
  */
 #include <assert.h>
 #include <os/os.h>
-#include <hal/hal_os_tick.h>
-#include <nrf52_bitfields.h>
-#include <bsp/cmsis_nvic.h>
+#include "syscfg/syscfg.h"
+#include "hal/hal_os_tick.h"
+#include "nrf52_bitfields.h"
+#include "bsp/cmsis_nvic.h"
 
-#if defined(BSP_HAS_32768_XTAL)
+#if MYNEWT_VAL(XTAL_32768)
 #define RTC_FREQ            32768       /* in Hz */
 #define OS_TICK_TIMER       NRF_RTC1
 #define OS_TICK_IRQ         RTC1_IRQn
@@ -85,7 +86,7 @@ nrf52_os_tick_counter(void)
      */
     OS_ASSERT_CRITICAL();
 
-#if defined(BSP_HAS_32768_XTAL)
+#if MYNEWT_VAL(XTAL_32768)
     return OS_TICK_TIMER->COUNTER;
 #else
     /*
@@ -103,7 +104,7 @@ nrf52_os_tick_set_ocmp(uint32_t ocmp)
 
     OS_ASSERT_CRITICAL();
     while (1) {
-#if defined(BSP_HAS_32768_XTAL)
+#if MYNEWT_VAL(XTAL_32768)
         int delta;
 
         ocmp &= 0xffffff;
@@ -143,7 +144,7 @@ nrf52_timer_handler(void)
     OS_ENTER_CRITICAL(sr);
 
     /* Calculate elapsed ticks and advance OS time. */
-#if defined(BSP_HAS_32768_XTAL)
+#if MYNEWT_VAL(XTAL_32768)
     int delta;
 
     counter = nrf52_os_tick_counter();
@@ -205,7 +206,7 @@ os_tick_idle(os_time_t ticks)
     }
 }
 
-#if defined(BSP_HAS_32768_XTAL)
+#if MYNEWT_VAL(XTAL_32768)
 void
 os_tick_init(uint32_t os_ticks_per_sec, int prio)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/hw/mcu/nordic/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/pkg.yml b/hw/mcu/nordic/pkg.yml
index 4c84dca..c695143 100644
--- a/hw/mcu/nordic/pkg.yml
+++ b/hw/mcu/nordic/pkg.yml
@@ -26,12 +26,12 @@ pkg.keywords:
 
 pkg.type: sdk
 
-pkg.ign_files.NRF52: 
+pkg.ign_files.BSP_NRF52: 
     - "nrf_drv_adc.c"
     - "pstorage*"
     - "sdk_mapped_flags.c"
 
-pkg.ign_files.NRF51:
+pkg.ign_files.BSP_NRF51:
     - "nrf_saadc.c"
     - "nrf_drv_saadc.c"
     - "nrf_drv_comp.c"
@@ -57,4 +57,3 @@ pkg.cflags: -std=gnu99 -DNRF52_PAN_28
 pkg.deps: 
     - hw/hal 
     - libs/cmsis-core 
-    - compiler/arm-none-eabi-m4

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/baselibc/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/baselibc/pkg.yml b/libs/baselibc/pkg.yml
index b0a947c..d7e3110 100644
--- a/libs/baselibc/pkg.yml
+++ b/libs/baselibc/pkg.yml
@@ -26,7 +26,3 @@ pkg.keywords:
 
 pkg.req_apis:
     - console
-pkg.features:
-    - LIBC
-    - BASELIBC
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bleuart/include/bleuart/bleuart.h
----------------------------------------------------------------------
diff --git a/libs/bleuart/include/bleuart/bleuart.h 
b/libs/bleuart/include/bleuart/bleuart.h
index 14ae930..6639747 100644
--- a/libs/bleuart/include/bleuart/bleuart.h
+++ b/libs/bleuart/include/bleuart/bleuart.h
@@ -20,12 +20,12 @@
 #ifndef _BLEUART_H_
 #define _BLEUART_H_
 
-int
-bleuart_init(int max_input);
+void
+bleuart_init(void);
 int
 bleuart_svc_register(void);
 int
-bleuart_gatt_svr_init(struct ble_hs_cfg *cfg);
+bleuart_gatt_svr_init(void);
 void
 bleuart_set_conn_handle(uint16_t conn_handle);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bleuart/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/bleuart/pkg.yml b/libs/bleuart/pkg.yml
index 5173293..272f53d 100644
--- a/libs/bleuart/pkg.yml
+++ b/libs/bleuart/pkg.yml
@@ -32,3 +32,11 @@ pkg.deps:
 
 pkg.req_apis:
     - console
+
+pkg.init_function: bleuart_init
+pkg.init_stage: 5
+
+pkg.syscfg_defs:
+    BLEUART_MAX_INPUT:
+        description: 'TBD'
+        value: 120

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bleuart/src/bleuart.c
----------------------------------------------------------------------
diff --git a/libs/bleuart/src/bleuart.c b/libs/bleuart/src/bleuart.c
index 81e433c..b7b2591 100644
--- a/libs/bleuart/src/bleuart.c
+++ b/libs/bleuart/src/bleuart.c
@@ -20,10 +20,12 @@
 #include <assert.h>
 #include <stdio.h>
 #include <string.h>
+
+#include "sysinit/sysinit.h"
 #include "host/ble_hs.h"
-#include <bleuart/bleuart.h>
-#include <os/endian.h>
-#include <console/console.h>
+#include "bleuart/bleuart.h"
+#include "os/endian.h"
+#include "console/console.h"
 
 /* ble uart attr read handle */
 uint16_t g_bleuart_attr_read_handle;
@@ -34,9 +36,6 @@ uint16_t g_bleuart_attr_write_handle;
 /* Pointer to a console buffer */
 char *console_buf;
 
-/* Console max input */
-uint16_t console_max_input;
-
 uint16_t g_console_conn_handle;
 /**
  * The vendor specific "bleuart" service consists of one write no-rsp 
characteristic
@@ -122,11 +121,11 @@ gatt_svr_chr_access_uart_write(uint16_t conn_handle, 
uint16_t attr_handle,
  * @return 0 on success; non-zero on failure
  */
 int
-bleuart_gatt_svr_init(struct ble_hs_cfg *cfg)
+bleuart_gatt_svr_init(void)
 {
     int rc;
 
-    rc = ble_gatts_count_cfg(gatt_svr_svcs, cfg);
+    rc = ble_gatts_count_cfg(gatt_svr_svcs);
     if (rc != 0) {
         goto err;
     }
@@ -154,7 +153,7 @@ bleuart_uart_read(void)
     off = 0;
     while (1) {
         rc = console_read(console_buf + off,
-                          console_max_input - off, &full_line);
+                          MYNEWT_VAL(BLEUART_MAX_INPUT) - off, &full_line);
         if (rc <= 0 && !full_line) {
             continue;
         }
@@ -189,16 +188,14 @@ bleuart_set_conn_handle(uint16_t conn_handle) {
  *
  * @param Maximum input
  */
-int
-bleuart_init(int max_input)
+void
+bleuart_init(void)
 {
     int rc;
 
     rc = console_init(bleuart_uart_read);
-    assert(rc == 0);
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
-    console_buf = malloc(max_input);
-    console_max_input = max_input;
-    assert(console_buf);
-    return 0;
+    console_buf = malloc(MYNEWT_VAL(BLEUART_MAX_INPUT));
+    SYSINIT_PANIC_ASSERT(console_buf != NULL);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/boot_serial/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/boot_serial/pkg.yml b/libs/boot_serial/pkg.yml
index 4a98343..b556e13 100644
--- a/libs/boot_serial/pkg.yml
+++ b/libs/boot_serial/pkg.yml
@@ -28,8 +28,8 @@ pkg.keywords:
 pkg.deps:
     - hw/hal
     - libs/os
-    - libs/testutil
     - libs/bootutil
     - libs/util
+
 pkg.req_apis:
     - console

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/boot_serial/src/test/boot_test.c
----------------------------------------------------------------------
diff --git a/libs/boot_serial/src/test/boot_test.c 
b/libs/boot_serial/src/test/boot_test.c
deleted file mode 100644
index e11a649..0000000
--- a/libs/boot_serial/src/test/boot_test.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * 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.
- */
-
-#include <assert.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <util/base64.h>
-#include <util/crc16.h>
-#include <testutil/testutil.h>
-#include <hal/hal_flash.h>
-#include <hal/flash_map.h>
-
-#include "../boot_serial_priv.h"
-
-void
-tx_msg(void *src, int len)
-{
-    char *msg;
-    char *enc;
-    int off;
-    uint16_t crc;
-
-    crc = htons(crc16_ccitt(CRC16_INITIAL_CRC, src, len));
-
-    /*
-     * Lazy, malloc a buffer, fill it and send it.
-     */
-    msg = malloc(len + 2 * sizeof(uint16_t));
-    assert(msg);
-
-    *(uint16_t *)msg = ntohs(len + sizeof(uint16_t));
-    off = sizeof(uint16_t);
-    memcpy(&msg[off], src, len);
-    off += len;
-    memcpy(&msg[off], &crc, sizeof(crc));
-    off += sizeof(uint16_t);
-
-    enc = malloc(BASE64_ENCODE_SIZE(off) + 1);
-    assert(enc);
-
-    off = base64_encode(msg, off, enc, 1);
-    assert(off > 0);
-
-    boot_serial_input(enc, off + 1);
-
-    free(enc);
-    free(msg);
-}
-
-TEST_CASE(boot_serial_setup)
-{
-
-}
-
-TEST_CASE(boot_serial_empty_msg)
-{
-    char buf[4];
-    struct nmgr_hdr hdr;
-
-    boot_serial_input(buf, 0);
-
-    tx_msg(buf, 0);
-
-    strcpy(buf, "--");
-    tx_msg(buf, 2);
-
-    memset(&hdr, 0, sizeof(hdr));
-    tx_msg(&hdr, sizeof(hdr));
-
-    hdr.nh_op = NMGR_OP_WRITE;
-
-    tx_msg(&hdr, sizeof(hdr));
-}
-
-TEST_CASE(boot_serial_empty_img_msg)
-{
-    char buf[sizeof(struct nmgr_hdr) + 32];
-    struct nmgr_hdr *hdr;
-
-    hdr = (struct nmgr_hdr *)buf;
-    memset(hdr, 0, sizeof(*hdr));
-    hdr->nh_op = NMGR_OP_WRITE;
-    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
-    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-    hdr->nh_len = htons(2);
-    strcpy((char *)(hdr + 1), "{}");
-
-    tx_msg(buf, sizeof(*hdr) + 2);
-}
-
-TEST_CASE(boot_serial_img_msg)
-{
-    char img[16];
-    char enc_img[BASE64_ENCODE_SIZE(sizeof(img))];
-    char buf[sizeof(struct nmgr_hdr) + sizeof(enc_img) + 32];
-    int len;
-    int rc;
-    struct nmgr_hdr *hdr;
-    const struct flash_area *fap;
-
-    memset(img, 0xa5, sizeof(img));
-    len = base64_encode(img, sizeof(img), enc_img, 1);
-    assert(len > 0);
-
-    hdr = (struct nmgr_hdr *)buf;
-    memset(hdr, 0, sizeof(*hdr));
-    hdr->nh_op = NMGR_OP_WRITE;
-    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
-    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-
-    len = sprintf((char *)(hdr + 1), "{\"off\":0,\"len\":16,\"data\":\"%s\"}",
-      enc_img);
-    hdr->nh_len = htons(len);
-
-    len = sizeof(*hdr) + len;
-
-    tx_msg(buf, len);
-
-    /*
-     * Validate contents inside image 0 slot
-     */
-    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
-    assert(rc == 0);
-
-    rc = flash_area_read(fap, 0, enc_img, sizeof(img));
-    assert(rc == 0);
-    assert(!memcmp(enc_img, img, sizeof(img)));
-}
-
-TEST_CASE(boot_serial_upload_bigger_image)
-{
-    char img[256];
-    char enc_img[64];
-    char buf[sizeof(struct nmgr_hdr) + 128];
-    int len;
-    int off;
-    int rc;
-    struct nmgr_hdr *hdr;
-    const struct flash_area *fap;
-    int i;
-
-    for (i = 0; i < sizeof(img); i++) {
-        img[i] = i;
-    }
-
-    for (off = 0; off < sizeof(img); off += 32) {
-        len = base64_encode(&img[off], 32, enc_img, 1);
-        assert(len > 0);
-
-        hdr = (struct nmgr_hdr *)buf;
-        memset(hdr, 0, sizeof(*hdr));
-        hdr->nh_op = NMGR_OP_WRITE;
-        hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
-        hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-
-        if (off) {
-            len = sprintf((char *)(hdr + 1), "{\"off\":%d,\"data\":\"%s\"}",
-              off, enc_img);
-        } else {
-            len = sprintf((char *)(hdr + 1), "{\"off\": 0 ,\"len\":%ld, "
-              "\"data\":\"%s\"}", (long)sizeof(img), enc_img);
-        }
-        hdr->nh_len = htons(len);
-
-        len = sizeof(*hdr) + len;
-
-        tx_msg(buf, len);
-    }
-
-    /*
-     * Validate contents inside image 0 slot
-     */
-    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
-    assert(rc == 0);
-
-    for (off = 0; off < sizeof(img); off += sizeof(enc_img)) {
-        rc = flash_area_read(fap, off, enc_img, sizeof(enc_img));
-        assert(rc == 0);
-        assert(!memcmp(enc_img, &img[off], sizeof(enc_img)));
-    }
-}
-
-TEST_SUITE(boot_serial_suite)
-{
-    boot_serial_setup();
-    boot_serial_empty_msg();
-    boot_serial_empty_img_msg();
-    boot_serial_img_msg();
-    boot_serial_upload_bigger_image();
-}
-
-int
-boot_serial_test(void)
-{
-    boot_serial_suite();
-    return tu_any_failed;
-}
-
-#ifdef MYNEWT_SELFTEST
-int
-main(void)
-{
-    tu_config.tc_print_results = 1;
-    tu_init();
-
-    boot_serial_test();
-
-    return tu_any_failed;
-}
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/boot_serial/test/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/boot_serial/test/pkg.yml b/libs/boot_serial/test/pkg.yml
new file mode 100644
index 0000000..e123ce1
--- /dev/null
+++ b/libs/boot_serial/test/pkg.yml
@@ -0,0 +1,30 @@
+# 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.
+#
+pkg.name: libs/boot_serial/test
+pkg.type: unittest
+pkg.description: "Boot serial unit tests."
+pkg.author: "Apache Mynewt <d...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+
+pkg.deps:
+    - libs/boot_serial
+    - libs/testutil
+
+pkg.deps.SELFTEST:
+    - libs/console/stub

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/boot_serial/test/src/boot_test.c
----------------------------------------------------------------------
diff --git a/libs/boot_serial/test/src/boot_test.c 
b/libs/boot_serial/test/src/boot_test.c
new file mode 100644
index 0000000..853a391
--- /dev/null
+++ b/libs/boot_serial/test/src/boot_test.c
@@ -0,0 +1,231 @@
+/*
+ * 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.
+ */
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "syscfg/syscfg.h"
+#include "util/base64.h"
+#include "util/crc16.h"
+#include "testutil/testutil.h"
+#include "hal/hal_flash.h"
+#include "hal/flash_map.h"
+
+#include "boot_serial_priv.h"
+
+void
+tx_msg(void *src, int len)
+{
+    char *msg;
+    char *enc;
+    int off;
+    uint16_t crc;
+
+    crc = htons(crc16_ccitt(CRC16_INITIAL_CRC, src, len));
+
+    /*
+     * Lazy, malloc a buffer, fill it and send it.
+     */
+    msg = malloc(len + 2 * sizeof(uint16_t));
+    assert(msg);
+
+    *(uint16_t *)msg = ntohs(len + sizeof(uint16_t));
+    off = sizeof(uint16_t);
+    memcpy(&msg[off], src, len);
+    off += len;
+    memcpy(&msg[off], &crc, sizeof(crc));
+    off += sizeof(uint16_t);
+
+    enc = malloc(BASE64_ENCODE_SIZE(off) + 1);
+    assert(enc);
+
+    off = base64_encode(msg, off, enc, 1);
+    assert(off > 0);
+
+    boot_serial_input(enc, off + 1);
+
+    free(enc);
+    free(msg);
+}
+
+TEST_CASE(boot_serial_setup)
+{
+
+}
+
+TEST_CASE(boot_serial_empty_msg)
+{
+    char buf[4];
+    struct nmgr_hdr hdr;
+
+    boot_serial_input(buf, 0);
+
+    tx_msg(buf, 0);
+
+    strcpy(buf, "--");
+    tx_msg(buf, 2);
+
+    memset(&hdr, 0, sizeof(hdr));
+    tx_msg(&hdr, sizeof(hdr));
+
+    hdr.nh_op = NMGR_OP_WRITE;
+
+    tx_msg(&hdr, sizeof(hdr));
+}
+
+TEST_CASE(boot_serial_empty_img_msg)
+{
+    char buf[sizeof(struct nmgr_hdr) + 32];
+    struct nmgr_hdr *hdr;
+
+    hdr = (struct nmgr_hdr *)buf;
+    memset(hdr, 0, sizeof(*hdr));
+    hdr->nh_op = NMGR_OP_WRITE;
+    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
+    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
+    hdr->nh_len = htons(2);
+    strcpy((char *)(hdr + 1), "{}");
+
+    tx_msg(buf, sizeof(*hdr) + 2);
+}
+
+TEST_CASE(boot_serial_img_msg)
+{
+    char img[16];
+    char enc_img[BASE64_ENCODE_SIZE(sizeof(img))];
+    char buf[sizeof(struct nmgr_hdr) + sizeof(enc_img) + 32];
+    int len;
+    int rc;
+    struct nmgr_hdr *hdr;
+    const struct flash_area *fap;
+
+    memset(img, 0xa5, sizeof(img));
+    len = base64_encode(img, sizeof(img), enc_img, 1);
+    assert(len > 0);
+
+    hdr = (struct nmgr_hdr *)buf;
+    memset(hdr, 0, sizeof(*hdr));
+    hdr->nh_op = NMGR_OP_WRITE;
+    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
+    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
+
+    len = sprintf((char *)(hdr + 1), "{\"off\":0,\"len\":16,\"data\":\"%s\"}",
+      enc_img);
+    hdr->nh_len = htons(len);
+
+    len = sizeof(*hdr) + len;
+
+    tx_msg(buf, len);
+
+    /*
+     * Validate contents inside image 0 slot
+     */
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    assert(rc == 0);
+
+    rc = flash_area_read(fap, 0, enc_img, sizeof(img));
+    assert(rc == 0);
+    assert(!memcmp(enc_img, img, sizeof(img)));
+}
+
+TEST_CASE(boot_serial_upload_bigger_image)
+{
+    char img[256];
+    char enc_img[64];
+    char buf[sizeof(struct nmgr_hdr) + 128];
+    int len;
+    int off;
+    int rc;
+    struct nmgr_hdr *hdr;
+    const struct flash_area *fap;
+    int i;
+
+    for (i = 0; i < sizeof(img); i++) {
+        img[i] = i;
+    }
+
+    for (off = 0; off < sizeof(img); off += 32) {
+        len = base64_encode(&img[off], 32, enc_img, 1);
+        assert(len > 0);
+
+        hdr = (struct nmgr_hdr *)buf;
+        memset(hdr, 0, sizeof(*hdr));
+        hdr->nh_op = NMGR_OP_WRITE;
+        hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
+        hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
+
+        if (off) {
+            len = sprintf((char *)(hdr + 1), "{\"off\":%d,\"data\":\"%s\"}",
+              off, enc_img);
+        } else {
+            len = sprintf((char *)(hdr + 1), "{\"off\": 0 ,\"len\":%ld, "
+              "\"data\":\"%s\"}", (long)sizeof(img), enc_img);
+        }
+        hdr->nh_len = htons(len);
+
+        len = sizeof(*hdr) + len;
+
+        tx_msg(buf, len);
+    }
+
+    /*
+     * Validate contents inside image 0 slot
+     */
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    assert(rc == 0);
+
+    for (off = 0; off < sizeof(img); off += sizeof(enc_img)) {
+        rc = flash_area_read(fap, off, enc_img, sizeof(enc_img));
+        assert(rc == 0);
+        assert(!memcmp(enc_img, &img[off], sizeof(enc_img)));
+    }
+}
+
+TEST_SUITE(boot_serial_suite)
+{
+    boot_serial_setup();
+    boot_serial_empty_msg();
+    boot_serial_empty_img_msg();
+    boot_serial_img_msg();
+    boot_serial_upload_bigger_image();
+}
+
+int
+boot_serial_test(void)
+{
+    boot_serial_suite();
+    return tu_any_failed;
+}
+
+#if MYNEWT_VAL(SELFTEST)
+int
+main(void)
+{
+    tu_config.tc_print_results = 1;
+    tu_init();
+
+    boot_serial_test();
+
+    return tu_any_failed;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bootutil/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/bootutil/pkg.yml b/libs/bootutil/pkg.yml
index 53c741c..f9d2f70 100644
--- a/libs/bootutil/pkg.yml
+++ b/libs/bootutil/pkg.yml
@@ -26,15 +26,24 @@ pkg.keywords:
     - bootloader
 
 pkg.deps: 
-    - libs/os 
-    - libs/testutil
-    - libs/mbedtls
     - hw/hal
+    - libs/mbedtls
+    - libs/os 
     - sys/config
 
-pkg.deps.FS:
-    - fs/fs
-pkg.cflags.NFFS: -DUSE_STATUS_FILE
+pkg.deps.BOOTUTIL_NFFS:
+    - fs/nffs
+
+pkg.init_function: bootutil_pkg_init
+pkg.init_stage: 5
 
-pkg.cflags.IMAGE_KEYS_RSA: -DIMAGE_SIGNATURES_RSA
-pkg.cflags.IMAGE_KEYS_EC: -DIMAGE_SIGNATURES_EC
+pkg.syscfg_defs:
+    BOOTUTIL_NFFS:
+        description: 'TBD'
+        value: 'MYNEWT_PKG_FS_NFFS'
+    BOOTUTIL_SIGN_RSA:
+        description: 'TBD'
+        value: '0'
+    BOOTUTIL_SIGN_EC:
+        description: 'TBD'
+        value: '0'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c 
b/libs/bootutil/src/bootutil_misc.c
index 94536ef..17052fe 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -19,22 +19,24 @@
 
 #include <string.h>
 #include <inttypes.h>
-#include <hal/hal_flash.h>
-#include <config/config.h>
-#include <os/os.h>
+
+#include "syscfg/syscfg.h"
+#include "hal/hal_flash.h"
+#include "config/config.h"
+#include "os/os.h"
 #include "bootutil/image.h"
 #include "bootutil_priv.h"
 
-#ifdef USE_STATUS_FILE
-#include <fs/fs.h>
-#include <fs/fsutil.h>
+#if MYNEWT_VAL(BOOTUTIL_NFFS)
+#include "fs/fs.h"
+#include "fs/fsutil.h"
 #endif
 
 static int boot_conf_set(int argc, char **argv, char *val);
 
 static struct image_version boot_main;
 static struct image_version boot_test;
-#ifndef USE_STATUS_FILE
+#if !MYNEWT_VAL(BOOTUTIL_NFFS)
 static struct boot_status boot_saved;
 #endif
 
@@ -69,7 +71,7 @@ boot_conf_set(int argc, char **argv, char *val)
                 memset(&boot_test, 0, len);
                 rc = 0;
             }
-#ifndef USE_STATUS_FILE
+#if !MYNEWT_VAL(BOOTUTIL_NFFS)
         } else if (!strcmp(argv[0], "status")) {
             if (!val) {
                 boot_saved.state = 0;
@@ -237,7 +239,7 @@ bootutil_cfg_register(void)
     conf_register(&boot_conf_handler);
 }
 
-#ifndef USE_STATUS_FILE
+#if !MYNEWT_VAL(BOOTUTIL_NFFS)
 int
 boot_read_status(struct boot_status *bs)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bootutil/src/image_ec.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/image_ec.c b/libs/bootutil/src/image_ec.c
index 6b21ab2..f3adfcf 100644
--- a/libs/bootutil/src/image_ec.c
+++ b/libs/bootutil/src/image_ec.c
@@ -16,13 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#ifdef IMAGE_SIGNATURES_EC
-#include <bootutil/sign_key.h>
 
-#include <mbedtls/sha256.h>
-#include <mbedtls/ecdsa.h>
-#include <mbedtls/oid.h>
-#include <mbedtls/asn1.h>
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(BOOTUTIL_SIGN_EC)
+#include "bootutil/sign_key.h"
+
+#include "mbedtls/sha256.h"
+#include "mbedtls/ecdsa.h"
+#include "mbedtls/oid.h"
+#include "mbedtls/asn1.h"
 
 #include "bootutil_priv.h"
 
@@ -115,4 +118,4 @@ bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t 
*sig, int slen,
 
     return rc;
 }
-#endif /* IMAGE_SIGNATURES_EC */
+#endif /* MYNEWT_VAL(BOOTUTIL_SIGN_EC) */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bootutil/src/image_rsa.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/image_rsa.c b/libs/bootutil/src/image_rsa.c
index 8f02329..e556092 100644
--- a/libs/bootutil/src/image_rsa.c
+++ b/libs/bootutil/src/image_rsa.c
@@ -16,11 +16,14 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#ifdef IMAGE_SIGNATURES_RSA
-#include <bootutil/sign_key.h>
 
-#include <mbedtls/rsa.h>
-#include <mbedtls/asn1.h>
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(BOOTUTIL_SIGN_RSA)
+#include "bootutil/sign_key.h"
+
+#include "mbedtls/rsa.h"
+#include "mbedtls/asn1.h"
 
 #include "bootutil_priv.h"
 
@@ -138,4 +141,4 @@ bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t 
*sig, int slen,
 
     return rc;
 }
-#endif /* IMAGE_SIGNATURES_RSA */
+#endif /* MYNEWT_VAL(BOOTUTIL_SIGN_RSA) */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bootutil/src/image_validate.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/image_validate.c 
b/libs/bootutil/src/image_validate.c
index b491790..17820aa 100644
--- a/libs/bootutil/src/image_validate.c
+++ b/libs/bootutil/src/image_validate.c
@@ -21,15 +21,16 @@
 #include <stddef.h>
 #include <inttypes.h>
 #include <string.h>
-#include <hal/hal_flash.h>
 
-#include <bootutil/image.h>
-#include <bootutil/sign_key.h>
+#include "syscfg/syscfg.h"
+#include "hal/hal_flash.h"
+#include "bootutil/image.h"
+#include "bootutil/sign_key.h"
 
-#include <mbedtls/sha256.h>
-#include <mbedtls/rsa.h>
-#include <mbedtls/ecdsa.h>
-#include <mbedtls/asn1.h>
+#include "mbedtls/sha256.h"
+#include "mbedtls/rsa.h"
+#include "mbedtls/ecdsa.h"
+#include "mbedtls/asn1.h"
 
 #include "bootutil_priv.h"
 
@@ -83,7 +84,7 @@ bootutil_img_validate(struct image_header *hdr, uint8_t 
flash_id, uint32_t addr,
     uint32_t off;
     uint32_t size;
     uint32_t sha_off = 0;
-#if defined(IMAGE_SIGNATURES_RSA) || defined(IMAGE_SIGNATURES_EC)
+#if MYNEWT_VAL(BOOTUTIL_SIGN_RSA) || MYNEWT_VAL(BOOTUTIL_SIGN_EC)
     uint32_t sig_off = 0;
     uint32_t sig_len = 0;
 #endif
@@ -92,12 +93,12 @@ bootutil_img_validate(struct image_header *hdr, uint8_t 
flash_id, uint32_t addr,
     uint8_t hash[32];
     int rc;
 
-#ifdef IMAGE_SIGNATURES_RSA
+#if MYNEWT_VAL(BOOTUTIL_SIGN_RSA)
     if ((hdr->ih_flags & IMAGE_F_PKCS15_RSA2048_SHA256) == 0) {
         return -1;
     }
 #endif
-#ifdef IMAGE_SIGNATURES_EC
+#if MYNEWT_VAL(BOOTUTIL_SIGN_EC)
     if ((hdr->ih_flags & IMAGE_F_ECDSA224_SHA256) == 0) {
         return -1;
     }
@@ -128,7 +129,7 @@ bootutil_img_validate(struct image_header *hdr, uint8_t 
flash_id, uint32_t addr,
             }
             sha_off = addr + off + sizeof(tlv);
         }
-#ifdef IMAGE_SIGNATURES_RSA
+#if MYNEWT_VAL(BOOTUTIL_SIGN_RSA)
         if (tlv.it_type == IMAGE_TLV_RSA2048) {
             if (tlv.it_len != 256) { /* 2048 bits */
                 return -1;
@@ -137,7 +138,7 @@ bootutil_img_validate(struct image_header *hdr, uint8_t 
flash_id, uint32_t addr,
             sig_len = tlv.it_len;
         }
 #endif
-#ifdef IMAGE_SIGNATURES_EC
+#if MYNEWT_VAL(BOOTUTIL_SIGN_EC)
         if (tlv.it_type == IMAGE_TLV_ECDSA224) {
             if (tlv.it_len < 64) { /* oids + 2 * 28 bytes */
                 return -1;
@@ -162,7 +163,7 @@ bootutil_img_validate(struct image_header *hdr, uint8_t 
flash_id, uint32_t addr,
             return -1;
         }
     }
-#if defined(IMAGE_SIGNATURES_RSA) || defined(IMAGE_SIGNATURES_EC)
+#if MYNEWT_VAL(BOOTUTIL_SIGN_RSA) || MYNEWT_VAL(BOOTUTIL_SIGN_EC)
     if (!sig_off) {
         /*
          * Header said there should be PKCS1.v5 signature, no TLV

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index bd7fbd8..6d08b9a 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -499,3 +499,9 @@ boot_go(const struct boot_req *req, struct boot_rsp *rsp)
 
     return 0;
 }
+
+void
+bootutil_pkg_init(void)
+{
+    bootutil_cfg_register();
+}

Reply via email to