Add BSP-specific files; remove non-BSP files.
diff --git a/$$pkgname.ld b/$$pkgname.ld
new file mode 100644
index 0000000..53baaed
--- /dev/null
+++ b/$$pkgname.ld
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+MEMORY
+{
+  FLASH (rx) : ORIGIN = 0x00008000, LENGTH = 0x3a000
+  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
+}
+
+/* This linker script is used for images and thus contains an image header */
+_imghdr_size = 0x20;
diff --git a/$$pkgname_debug.sh b/$$pkgname_debug.sh
new file mode 100755
index 0000000..6dd8648
--- /dev/null
+++ b/$$pkgname_debug.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# This script attaches a gdb session to a Mynewt image running on your BSP.
+
+# If your BSP uses JLink, a good example script to copy is:
+#     repos/apache-mynewt-core/hw/bsp/nrf52dk/nrf52dk_debug.sh
+#
+# If your BSP uses OpenOCD, a good example script to copy is:
+#     repos/apache-mynewt-core/hw/bsp/rb-nano2/rb-nano2_debug.sh
diff --git a/$$pkgname_download.sh b/$$pkgname_download.sh
new file mode 100755
index 0000000..22dc56a
--- /dev/null
+++ b/$$pkgname_download.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# This script uploads a Mynewt image to your BSP.
+
+# If your BSP uses JLink, a good example script to copy is:
+#     repos/apache-mynewt-core/hw/bsp/nrf52dk/nrf52dk_download.sh
+#
+# If your BSP uses OpenOCD, a good example script to copy is:
+#     repos/apache-mynewt-core/hw/bsp/rb-nano2/rb-nano2_download.sh
diff --git a/README.md b/README.md
index 57d8245..6b1ec5c 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,18 @@
-# Sample Package Definition
+# Sample BSP Definition
 
-This is a basic definition of a sample Mynewt package.
+This is a basic definition of a sample Mynewt BSP package.  See
+https://mynewt.apache.org/latest/os/core_os/porting/port_bsp/ for documentation
+on creating a Mynewt BSP package.
 
 The source files are located in the src/ directory.
 
 Header files are located in include/ 
 
-pkg.yml contains the base definition of the package.
+pkg.yml contains the base definition of the BSP package.
+
+bsp.yml contains BSP-specific settings.
+
+syscfg.yml contains Mynewt setting definitions and overrides.
 
 Any questions?  Please refer to the documentation at 
 http://mynewt.apache.org/ or ask questions on dev@mynewt.apache.org
diff --git a/boot-$$pkgname.ld b/boot-$$pkgname.ld
new file mode 100644
index 0000000..d1f1b99
--- /dev/null
+++ b/boot-$$pkgname.ld
@@ -0,0 +1,25 @@
+/* Linker script for Nordic Semiconductor nRF5 devices
+ *
+ * Version: Sourcery G++ 4.5-1
+ * Support: https://support.codesourcery.com/GNUToolchain/
+ *
+ * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc.
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions.  No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+MEMORY
+{
+  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x4000
+  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
+}
+
+/* The bootloader does not contain an image header */
+_imghdr_size = 0x0;
diff --git a/bsp.yml b/bsp.yml
new file mode 100644
index 0000000..92a8667
--- /dev/null
+++ b/bsp.yml
@@ -0,0 +1,66 @@
+#
+# 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.
+#
+
+### Entries containing `XXX` need to be replaced with actual values.
+
+bsp.arch: # XXX <MCU-architecture>
+bsp.compiler: # XXX <compiler-package>
+bsp.linkerscript:
+    - '$$pkgfullname/$$pkgname.ld'
+    # - XXX mcu-linker-script
+bsp.linkerscript.BOOT_LOADER.OVERWRITE:
+    - '$$pkgfullname/boot-$$pkgname.ld'
+    # - XXX mcu-linker-script
+bsp.part2linkerscript: "$$pkgfullname/split-$$pkgname.ld"
+bsp.downloadscript: "$$pkgfullname/$$pkgname_download.sh"
+bsp.debugscript: "$$pkgfullname/$$pkgname_debug.sh"
+bsp.downloadscript.WINDOWS.OVERWRITE: "$$pkgfullname/$$pkgname_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "$$pkgfullname/$$pkgname_debug.cmd"
+
+bsp.flash_map:
+    areas:
+        # System areas.
+        FLASH_AREA_BOOTLOADER:
+            device: 0
+            offset: 0x00000000
+            size: 16kB
+        FLASH_AREA_IMAGE_0:
+            device: 0
+            offset: 0x00008000
+            size: 232kB
+        FLASH_AREA_IMAGE_1:
+            device: 0
+            offset: 0x00042000
+            size: 232kB
+        FLASH_AREA_IMAGE_SCRATCH:
+            device: 0
+            offset: 0x0007c000
+            size: 4kB
+
+        # User areas.
+        FLASH_AREA_REBOOT_LOG:
+            user_id: 0
+            device: 0
+            offset: 0x00004000
+            size: 16kB
+        FLASH_AREA_NFFS:
+            user_id: 1
+            device: 0
+            offset: 0x0007d000
+            size: 12kB
diff --git a/include/bsp/bsp.h b/include/bsp/bsp.h
new file mode 100644
index 0000000..fc5915d
--- /dev/null
+++ b/include/bsp/bsp.h
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+#ifndef H_BSP_
+#define H_BSP_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Defined in MCU linker script. */
+extern uint8_t _ram_start;
+
+#define RAM_SIZE        0x10000
+
+/* Put additional BSP definitions here. */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/your-path/your-file.h b/include/your-path/your-file.h
deleted file mode 100644
index 8716e48..0000000
--- a/include/your-path/your-file.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * This is a sample header file for your package.  Feel free to delete this
- * file, or rename it.
- *
- * Package include files are located under the <pkg>/include/<pkg-name>
- * directory.  When referencing include files in this directory, the
- * include statement should be:
- *
- * #include "pkg-name/file-name.h"
- *
- * If you are referencing package includes from another package, you must
- * list the package who's includes you are referencing as a dependency in
- * the pkg.yml file.  By adding the package as a dependency, newt will
- * automatically add -I<pkg>/include to the CFLAGS when compiling your
- * package.
- *
- * If you want to provide architecture specific header files, you can do
- * this by putting it into the "arch/your-arch/pkg-name".  For example,
- * to have a header file that is overrode for Cortex-M4 architectures, you
- * would put the file in the following location:
- *
- * * <your-pkg>/include/<your-pkg>/arch/cortex_m4/<your-pkg>/file-name.h
- *
- * And you can then include it with the following include statement:
- *
- * #include "pkg-name/file-name.h"
- *
- * And depending on what architecture is specified (usually controlled by
- * BSP or MCU definition), the correct architecture directory will be
- * included.
- */
diff --git a/pkg.yml b/pkg.yml
index 4e16759..84ac3d6 100644
--- a/pkg.yml
+++ b/pkg.yml
@@ -17,10 +17,18 @@
 # under the License.
 #
 
+### Entries containing `***` need to be replaced with actual values.
+
 pkg.name: your-pkg-name
+pkg.type: bsp
 pkg.description: "Description of your package"
 pkg.author: "You <you@you.org>"
 pkg.homepage: "http://your-url.org/"
 pkg.keywords:
 
+pkg.cflags:
+
 pkg.deps:
+    # - *** <MCU-package>
+    - '@apache-mynewt-core/kernel/os'
+    - '@apache-mynewt-core/libc/baselibc'
diff --git a/src/hal_bsp.c b/src/hal_bsp.c
new file mode 100644
index 0000000..70bf2a3
--- /dev/null
+++ b/src/hal_bsp.c
@@ -0,0 +1,82 @@
+#include <inttypes.h>
+#include <assert.h>
+#include "syscfg/syscfg.h"
+#include "sysflash/sysflash.h"
+#include "hal/hal_system.h"
+#include "hal/hal_flash_int.h"
+#include "hal/hal_timer.h"
+#include "hal/hal_bsp.h"
+#include "os/os.h"
+#include "bsp/bsp.h"
+
+/** What memory to include in coredump. */
+static const struct hal_bsp_mem_dump dump_cfg[] = {
+    [0] = {
+        .hbmd_start = &_ram_start,
+        .hbmd_size = RAM_SIZE,
+    }
+};
+
+const struct hal_bsp_mem_dump *
+hal_bsp_core_dump(int *area_cnt)
+{
+    *area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
+    return dump_cfg;
+}
+
+/**
+ * Retrieves the flash device with the specified ID.  Returns NULL if no such
+ * device exists.
+ */
+const struct hal_flash *
+hal_bsp_flash_dev(uint8_t id)
+{
+    switch (id) {
+    case 0:
+        /* MCU internal flash. */
+        /* XXX: Return pointer to MCU's flash object. */
+        return NULL;
+
+    default:
+        /* External flash.  Assume not present in this BSP. */
+        return NULL;
+    }
+}
+
+/**
+ * Retrieves the configured priority for the given interrupt. If no priority
+ * is configured, returns the priority passed in.
+ *
+ * @param irq_num               The IRQ being queried.
+ * @param pri                   The default priority if none is configured.
+ *
+ * @return uint32_t             The specified IRQ's priority.
+ */
+uint32_t
+hal_bsp_get_nvic_priority(int irq_num, uint32_t pri)
+{
+    return pri;
+}
+
+void
+hal_bsp_init(void)
+{
+    int rc;
+
+    (void)rc;
+
+    /* Make sure system clocks have started. */
+    hal_system_clock_start();
+
+#if MYNEWT_VAL(TIMER_0)
+    rc = hal_timer_init(0, NULL);
+    assert(rc == 0);
+#endif
+
+#if (MYNEWT_VAL(OS_CPUTIME_TIMER_NUM) >= 0)
+    rc = os_cputime_init(MYNEWT_VAL(OS_CPUTIME_FREQ));
+    assert(rc == 0);
+#endif
+
+    /* Initialize additional BSP peripherals here. */
+}
diff --git a/src/sbrk.c b/src/sbrk.c
new file mode 100644
index 0000000..3fe253e
--- /dev/null
+++ b/src/sbrk.c
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+/* put these in the data section so they are not cleared by _start */
+static char *sbrkBase __attribute__ ((section (".data")));
+static char *sbrkLimit __attribute__ ((section (".data")));
+static char *brk __attribute__ ((section (".data")));
+
+void
+_sbrkInit(char *base, char *limit) {
+    sbrkBase = base;
+    sbrkLimit = limit;
+    brk = base;
+}
+
+void *
+_sbrk(int incr)
+{
+    void *prev_brk;
+
+    if (incr < 0) {
+        /* Returning memory to the heap. */
+        incr = -incr;
+        if (brk - incr < sbrkBase) {
+            prev_brk = (void *)-1;
+        } else {
+            prev_brk = brk;
+            brk -= incr;
+        }
+    } else {
+        /* Allocating memory from the heap. */
+        if (sbrkLimit - brk >= incr) {
+            prev_brk = brk;
+            brk += incr;
+        } else {
+            prev_brk = (void *)-1;
+        }
+    }
+
+    return prev_brk;
+}
diff --git a/src/your-source.c b/src/your-source.c
deleted file mode 100644
index 2f8c1dc..0000000
--- a/src/your-source.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Depending on the type of package, there are different
- * compilation rules for this directory.  This comment applies
- * to packages of type "pkg."  For other types of packages,
- * please view the documentation at http://mynewt.apache.org/.
- *
- * Put source files in this directory.  All files that have a *.c
- * ending are recursively compiled in the src/ directory and its
- * descendants.  The exception here is the arch/ directory, which
- * is ignored in the default compilation.
- *
- * The arch/<your-arch>/ directories are manually added and
- * recursively compiled for all files that end with either *.c
- * or *.a.  Any directories in arch/ that don't match the
- * architecture being compiled are not compiled.
- *
- * Architecture is set by the BSP/MCU combination.
- */
diff --git a/syscfg.yml b/syscfg.yml
new file mode 100644
index 0000000..817d4c6
--- /dev/null
+++ b/syscfg.yml
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+# Settings this BSP defines.
+syscfg.defs:
+    TIMER_0:
+        description: 'Timer 0'
+        value:  1
+
+# Settings this BSP overrides.
+syscfg.vals: