From 65806f53ebffae14278f6c051ff4a7634b9aea22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Wed, 27 Nov 2013 21:49:24 +0100 Subject: [PATCH 1/2] cc2538dk: startup-gcc: Do not redefine SYS_CTRL_EMUOVR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SYS_CTRL_EMUOVR is already defined in sys-ctrl.h, so #include this header file instead of redefining SYS_CTRL_EMUOVR in startup-gcc.c. Signed-off-by: Benoît Thébaudeau --- platform/cc2538dk/startup-gcc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/cc2538dk/startup-gcc.c b/platform/cc2538dk/startup-gcc.c index 239f5a3d4..ce4768fb2 100644 --- a/platform/cc2538dk/startup-gcc.c +++ b/platform/cc2538dk/startup-gcc.c @@ -38,13 +38,13 @@ */ #include "contiki.h" #include "reg.h" +#include "sys-ctrl.h" #include "uart.h" #include #define FLASH_START_ADDR 0x00200000 #define BOOTLOADER_BACKDOOR_DISABLE 0xEFFFFFFF -#define SYS_CTRL_EMUOVR 0x400D20B4 /*---------------------------------------------------------------------------*/ extern int main(void); /*---------------------------------------------------------------------------*/ From a2686e581eb1d27356aa0a008b88afd6ec1d2433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Wed, 27 Nov 2013 21:55:18 +0100 Subject: [PATCH 2/2] cc2538: Add header file for flash CCA page and use it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create a dedicated header file with all the definitions for the flash lock bit page and customer configuration area. This avoids duplicating those definitions in the startup-gcc.c files of all CC2538-based platforms, and this also allows to easily manipulate the CCA from outside startup-gcc.c (e.g. for on-the-air firmware update). The definitions are now complete contrary to what was in startup-gcc.c: - Definitions have been added to select the bootloader backdoor pin and active level if enabled. - Definitions have been added to access the page and debug lock bits. The debug lock bit can be used to prevent someone from reading back a programmed firmware through JTAG if the firmware binary image has to be confidential, which should be combined with a disabled bootloader backdoor. - The application entry point is now tied to the beginning of the .text section instead of to the beginning of the flash. This allows projects using custom linker scripts to place the application entry point anywhere in the flash, which can be useful e.g. for on-the-air firmware update. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/cc2538.lds | 2 +- cpu/cc2538/dev/flash-cca.h | 93 +++++++++++++++++++++++++++++++++ platform/cc2538dk/startup-gcc.c | 29 +++++----- 3 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 cpu/cc2538/dev/flash-cca.h diff --git a/cpu/cc2538/cc2538.lds b/cpu/cc2538/cc2538.lds index 6ed024a30..635ec454b 100644 --- a/cpu/cc2538/cc2538.lds +++ b/cpu/cc2538/cc2538.lds @@ -46,7 +46,7 @@ MEMORY { FLASH (rx) : ORIGIN = 0x200000, LENGTH = 0x0007FFD4 - FLASH_CCA (RX) : ORIGIN = 0x0027FFD4, LENGTH = 12 + FLASH_CCA (RX) : ORIGIN = 0x0027FFD4, LENGTH = 44 #if (LPM_CONF_MAX_PM==2) && (LPM_CONF_ENABLE != 0) NRSRAM (RWX) : ORIGIN = NRSRAM_START, LENGTH = NRSRAM_LEN #endif diff --git a/cpu/cc2538/dev/flash-cca.h b/cpu/cc2538/dev/flash-cca.h new file mode 100644 index 000000000..2dff2978b --- /dev/null +++ b/cpu/cc2538/dev/flash-cca.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/ + * All rights reserved. + * + * Copyright (c) 2013, ADVANSEE - http://www.advansee.com/ + * Benoît Thébaudeau + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \addtogroup cc2538 + * @{ + * + * \defgroup cc2538-flash-cca cc2538 flash CCA + * + * Definitions for the cc2538 flash lock bit page and customer configuration + * area + * @{ + * + * \file + * Header file for the flash lock bit page and CCA definitions + */ +#ifndef FLASH_CCA_H_ +#define FLASH_CCA_H_ + +#include +/*---------------------------------------------------------------------------*/ +/** \name Bootloader backdoor configuration bit fields + * @{ + */ +#define FLASH_CCA_BOOTLDR_CFG_DISABLE 0xEFFFFFFF /**< Disable backdoor function */ +#define FLASH_CCA_BOOTLDR_CFG_ENABLE 0xF0FFFFFF /**< Enable backdoor function */ +#define FLASH_CCA_BOOTLDR_CFG_ACTIVE_HIGH 0x08000000 /**< Selected pin on pad A active high */ +#define FLASH_CCA_BOOTLDR_CFG_PORT_A_PIN_M 0x07000000 /**< Selected pin on pad A mask */ +#define FLASH_CCA_BOOTLDR_CFG_PORT_A_PIN_S 24 /**< Selected pin on pad A shift */ +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name Image valid definitions + * @{ + */ +#define FLASH_CCA_IMAGE_VALID 0x00000000 /**< Indicates valid image in flash */ +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name Lock page / debug definitions + * @{ + */ +#define FLASH_CCA_LOCKED 0 /**< Page or debug locked if bit == 0 */ +#define FLASH_CCA_LOCK_DEBUG_BYTE 31 /**< Lock byte containing the debug lock bit */ +#define FLASH_CCA_LOCK_DEBUG_BIT 7 /**< Debug lock bit position in the corresponding lock byte */ +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name Flash lock bit page and CCA layout + * @{ + */ +typedef struct { + uint32_t bootldr_cfg; /**< Bootloader backdoor configuration (page bytes 2004 - 2007) */ + uint32_t image_valid; /**< Image valid (page bytes 2008 - 2011) */ + const void *app_entry_point; /**< Flash vector table address (page bytes 2012 - 2015) */ + uint8_t lock[32]; /**< Page and debug lock bits (page bytes 2016 - 2047) */ +} flash_cca_lock_page_t; +/** @} */ + +#endif /* FLASH_CCA_H_ */ + +/** + * @} + * @} + */ diff --git a/platform/cc2538dk/startup-gcc.c b/platform/cc2538dk/startup-gcc.c index ce4768fb2..0c7587e45 100644 --- a/platform/cc2538dk/startup-gcc.c +++ b/platform/cc2538dk/startup-gcc.c @@ -38,13 +38,11 @@ */ #include "contiki.h" #include "reg.h" +#include "flash-cca.h" #include "sys-ctrl.h" #include "uart.h" #include - -#define FLASH_START_ADDR 0x00200000 -#define BOOTLOADER_BACKDOOR_DISABLE 0xEFFFFFFF /*---------------------------------------------------------------------------*/ extern int main(void); /*---------------------------------------------------------------------------*/ @@ -92,22 +90,19 @@ void uart_isr(void); /* Allocate stack space */ static unsigned long stack[512]; /*---------------------------------------------------------------------------*/ -/* - * Customer Configuration Area in the Lock Page - * Holds Image Vector table address (bytes 2012 - 2015) and - * Image Valid bytes (bytes 2008 -2011) - */ -typedef struct { - unsigned long bootldr_cfg; - unsigned long image_valid; - unsigned long image_vector_addr; -} lock_page_cca_t; +/* Linker construct indicating .text section location */ +extern uint8_t _text[0]; /*---------------------------------------------------------------------------*/ __attribute__ ((section(".flashcca"), used)) -const lock_page_cca_t __cca = { - BOOTLOADER_BACKDOOR_DISABLE, /* Bootloader backdoor disabled */ - 0, /* Image valid bytes */ - FLASH_START_ADDR /* Vector table located at the start of flash */ +const flash_cca_lock_page_t __cca = { + FLASH_CCA_BOOTLDR_CFG_DISABLE, /* Bootloader backdoor disabled */ + FLASH_CCA_IMAGE_VALID, /* Image valid */ + &_text, /* Vector table located at the start of .text */ + /* Unlock all pages and debug */ + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }; /*---------------------------------------------------------------------------*/ __attribute__ ((section(".vectors"), used))