You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/02/03 21:55:27 UTC

[2/3] incubator-mynewt-larva git commit: Add bootloader support for NRF51.

Add bootloader support for NRF51.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/ed475f01
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/ed475f01
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/ed475f01

Branch: refs/heads/master
Commit: ed475f016706ea5541a4589a4816a32f039e7803
Parents: 4dfea58
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Feb 3 12:54:39 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Feb 3 12:54:39 2016 -0800

----------------------------------------------------------------------
 hw/bsp/nrf51dk/boot-nrf51dk.ld     | 194 ++++++++++++++++++++++++++++++++
 hw/bsp/nrf51dk/egg.yml             |   2 +-
 hw/bsp/nrf51dk/nrf51dk.ld          |   8 +-
 hw/bsp/nrf51dk/nrf51dk_download.sh |  58 ++++++++--
 hw/bsp/nrf51dk/src/os_bsp.c        |  27 ++---
 5 files changed, 261 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed475f01/hw/bsp/nrf51dk/boot-nrf51dk.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/boot-nrf51dk.ld b/hw/bsp/nrf51dk/boot-nrf51dk.ld
new file mode 100755
index 0000000..85690fd
--- /dev/null
+++ b/hw/bsp/nrf51dk/boot-nrf51dk.ld
@@ -0,0 +1,194 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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.
+ */
+
+/* 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.
+ */
+OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
+
+MEMORY
+{
+  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x7000
+  RAM (rwx) :  ORIGIN = 0x20000000, LENGTH = 0x8000
+}
+
+/* Linker script to place sections and symbol values. Should be used together
+ * with other linker script that defines memory regions FLASH and RAM.
+ * It references following symbols, which must be defined in code:
+ *   Reset_Handler : Entry of reset handler
+ * 
+ * It defines following symbols, which code can use without definition:
+ *   __exidx_start
+ *   __exidx_end
+ *   __etext
+ *   __data_start__
+ *   __preinit_array_start
+ *   __preinit_array_end
+ *   __init_array_start
+ *   __init_array_end
+ *   __fini_array_start
+ *   __fini_array_end
+ *   __data_end__
+ *   __bss_start__
+ *   __bss_end__
+ *   __HeapBase
+ *   __HeapLimit
+ *   __StackLimit
+ *   __StackTop
+ *   __stack
+ *   __bssnz_start__
+ *   __bssnz_end__
+ */
+ENTRY(Reset_Handler)
+
+SECTIONS
+{
+    .text :
+    {
+        __isr_vector_start = .;
+        KEEP(*(.isr_vector))
+        __isr_vector_end = .;
+        *(.text*)
+
+        KEEP(*(.init))
+        KEEP(*(.fini))
+
+        /* .ctors */
+        *crtbegin.o(.ctors)
+        *crtbegin?.o(.ctors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
+        *(SORT(.ctors.*))
+        *(.ctors)
+
+        /* .dtors */
+        *crtbegin.o(.dtors)
+        *crtbegin?.o(.dtors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
+        *(SORT(.dtors.*))
+        *(.dtors)
+
+        *(.rodata*)
+
+        *(.eh_frame*)
+        . = ALIGN(4);
+    } > FLASH
+
+
+    .ARM.extab : 
+    {
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
+        . = ALIGN(4);
+    } > FLASH
+
+    __exidx_start = .;
+    .ARM.exidx :
+    {
+        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+        . = ALIGN(4);
+    } > FLASH
+    __exidx_end = .;
+
+    __etext = .;
+
+    .vector_relocation :
+    {
+        . = ALIGN(4);
+        __vector_tbl_reloc__ = .;
+        . = . + (__isr_vector_end - __isr_vector_start);
+        . = ALIGN(4);
+    } > RAM
+            
+    .data : AT (__etext)
+    {
+        __data_start__ = .;
+        *(vtable)
+        *(.data*)
+
+        . = ALIGN(4);
+        /* preinit data */
+        PROVIDE_HIDDEN (__preinit_array_start = .);
+        *(.preinit_array)
+        PROVIDE_HIDDEN (__preinit_array_end = .);
+
+        . = ALIGN(4);
+        /* init data */
+        PROVIDE_HIDDEN (__init_array_start = .);
+        *(SORT(.init_array.*))
+        *(.init_array)
+        PROVIDE_HIDDEN (__init_array_end = .);
+
+
+        . = ALIGN(4);
+        /* finit data */
+        PROVIDE_HIDDEN (__fini_array_start = .);
+        *(SORT(.fini_array.*))
+        *(.fini_array)
+        PROVIDE_HIDDEN (__fini_array_end = .);
+
+        *(.jcr)
+        . = ALIGN(4);
+        /* All data end */
+        __data_end__ = .;
+    } > RAM
+
+    .bss :
+    {
+        . = ALIGN(4);
+        __bss_start__ = .;
+        *(.bss*)
+        *(COMMON)
+        . = ALIGN(4);
+        __bss_end__ = .;
+    } > RAM
+
+    /* Heap starts after BSS */
+    __HeapBase = .;
+
+    /* .stack_dummy section doesn't contains any symbols. It is only
+     * used for linker to calculate size of stack sections, and assign
+     * values to stack symbols later */
+    .stack_dummy (COPY):
+    {
+        *(.stack*)
+    } > RAM
+
+    /* Set stack top to end of RAM, and stack limit move down by
+     * size of stack_dummy section */
+    __StackTop = ORIGIN(RAM) + LENGTH(RAM);
+    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
+    PROVIDE(__stack = __StackTop);
+
+    /* Top of head is the bottom of the stack */
+    __HeapLimit = __StackLimit;
+
+    /* Check if data + heap + stack exceeds RAM limit */
+    ASSERT(__HeapBase <= __HeapLimit, "region RAM overflowed with stack")
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed475f01/hw/bsp/nrf51dk/egg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/egg.yml b/hw/bsp/nrf51dk/egg.yml
index dd7d80a..19858fc 100644
--- a/hw/bsp/nrf51dk/egg.yml
+++ b/hw/bsp/nrf51dk/egg.yml
@@ -1,6 +1,6 @@
 egg.name: "hw/bsp/nrf51dk"
 egg.linkerscript: "nrf51dk.ld" 
-egg.linkerscript.bootloader.OVERWRITE: "boot-nrf51pdk.ld"
+egg.linkerscript.bootloader.OVERWRITE: "boot-nrf51dk.ld"
 egg.downloadscript: nrf51dk_download.sh
 egg.debugscript: nrf51dk_debug.sh
 egg.cflags: -DNRF51

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed475f01/hw/bsp/nrf51dk/nrf51dk.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/nrf51dk.ld b/hw/bsp/nrf51dk/nrf51dk.ld
index 24e0c35..18ac8c9 100755
--- a/hw/bsp/nrf51dk/nrf51dk.ld
+++ b/hw/bsp/nrf51dk/nrf51dk.ld
@@ -35,7 +35,7 @@ OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
 
 MEMORY
 {
-  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x40000
+  FLASH (rx) : ORIGIN = 0x00007000, LENGTH = 0x1c000
   RAM (rwx) :  ORIGIN = 0x20000000, LENGTH = 0x8000
 }
 
@@ -70,6 +70,11 @@ ENTRY(Reset_Handler)
 
 SECTIONS
 {
+    .imghdr (NOLOAD):
+    {
+    	. = . + 0x20;
+    } > FLASH
+
     .text :
     {
         __isr_vector_start = .;
@@ -117,6 +122,7 @@ SECTIONS
 
     __etext = .;
 
+    /* Keep first in RAM, as well as in bootloader */
     .vector_relocation :
     {
         . = ALIGN(4);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed475f01/hw/bsp/nrf51dk/nrf51dk_download.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/nrf51dk_download.sh b/hw/bsp/nrf51dk/nrf51dk_download.sh
index b921d38..c860c0e 100755
--- a/hw/bsp/nrf51dk/nrf51dk_download.sh
+++ b/hw/bsp/nrf51dk/nrf51dk_download.sh
@@ -12,23 +12,61 @@ if [ $# -lt 1 ]; then
     exit 1
 fi
 
-FLASH_OFFSET=0x0
-FILE_NAME=$1.elf.bin
-JLINK_SCRIPT=.download.jlink
+IS_BOOTLOADER=0
+BASENAME=$1
+BIN2IMG=project/bin2img/bin/bin2img/bin2img.elf
+VER=11.22.33.0
+#JLINK_SCRIPT=.download.jlink
+GDB_CMD_FILE=.gdb_cmds
+
+# Look for 'bootloader' from 2nd arg onwards
+shift
+while [ $# -gt 0 ]; do
+    if [ $1 == "bootloader" ]; then
+	IS_BOOTLOADER=1
+    fi
+    shift
+done
+
+if [ $IS_BOOTLOADER -eq 1 ]; then
+    FLASH_OFFSET=0x0
+    FILE_NAME=$BASENAME.elf.bin
+else
+    FLASH_OFFSET=0x7000
+    FILE_NAME=$BASENAME.elf.img
+    echo "Version is >" $VER "<"
+    $BIN2IMG $BASENAME.elf.bin $FILE_NAME $VER
+    if [ "$?" -ne 0 ]; then
+	exit 1
+    fi
+fi
 
 echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
 
-cat > $JLINK_SCRIPT <<EOF
-w 4001e504 1
-loadbin $FILE_NAME $FLASH_OFFSET
-q
-EOF
+# XXX for some reason JLinkExe overwrites flash at offset 0 when
+# downloading somewhere in the flash. So need to figure out how to tell it
+# not to do that, or report failure if gdb fails to write this file
+# 
+echo "shell /bin/sh -c 'trap \"\" 2;JLinkGDBServer -device nRF51422_xxAC -speed 4000 -if SWD -port 3333 -singlerun' & " > $GDB_CMD_FILE
+echo "target remote localhost:3333" >> $GDB_CMD_FILE
+echo "restore $FILE_NAME binary $FLASH_OFFSET" >> $GDB_CMD_FILE
+echo "quit" >> $GDB_CMD_FILE
+
+msgs=`arm-none-eabi-gdb -x $GDB_CMD_FILE`
+
+rm $GDB_CMD_FILE
+
+#cat > $JLINK_SCRIPT <<EOF
+#w 4001e504 1
+#loadbin $FILE_NAME,$FLASH_OFFSET
+#q
+#EOF
 
-msgs=`JLinkExe -device nRF51422_xxAC -speed 4000 -if SWD $JLINK_SCRIPT`
+#msgs=`JLinkExe -device nRF51422_xxAC -speed 4000 -if SWD $JLINK_SCRIPT`
 
 # Echo output from script run, so newt can show it if things go wrong.
 echo $msgs
-rm $JLINK_SCRIPT
+#rm $JLINK_SCRIPT
 
 error=`echo $msgs | grep error`
 if [ -n "$error" ]; then

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ed475f01/hw/bsp/nrf51dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/os_bsp.c b/hw/bsp/nrf51dk/src/os_bsp.c
index 3e28df3..1596d2e 100644
--- a/hw/bsp/nrf51dk/src/os_bsp.c
+++ b/hw/bsp/nrf51dk/src/os_bsp.c
@@ -20,36 +20,31 @@
 #include "mcu/nrf51_hal.h"
 
 static struct flash_area bsp_flash_areas[] = {
-#if 0
     [FLASH_AREA_BOOTLOADER] = {
         .fa_flash_id = 0,       /* internal flash */
-        .fa_off = 0x08000000,   /* beginning */
-        .fa_size = (32 * 1024)
+        .fa_off = 0x00000000,   /* beginning */
+        .fa_size = (28 * 1024)
     },
-#endif
-    /* 2 * 16K and 1*64K sectors here */
     [FLASH_AREA_IMAGE_0] = {
         .fa_flash_id = 0,
-        .fa_off = 0x00000000,
-        .fa_size = (232 * 1024)
-    }
-#if 0
+        .fa_off = 0x00007000,
+        .fa_size = (112 * 1024)
+    },
     [FLASH_AREA_IMAGE_1] = {
         .fa_flash_id = 0,
-        .fa_off = 0x00042000,
-        .fa_size = (232 * 1024)
+        .fa_off = 0x00023000,
+        .fa_size = (112 * 1024)
     },
     [FLASH_AREA_IMAGE_SCRATCH] = {
         .fa_flash_id = 0,
-        .fa_off = 0x0007c000,
-        .fa_size = (4 * 1024)
+        .fa_off = 0x0003f000,
+        .fa_size = (1 * 1024)
     },
     [FLASH_AREA_NFFS] = {
         .fa_flash_id = 0,
-        .fa_off = 0x0007d000,
-        .fa_size = (12 * 1024)
+        .fa_off = 0x0003f400,
+        .fa_size = (3 * 1024)
     }
-#endif
 };
 
 void *_sbrk(int incr);