cc2538: Define and use device features

Define the available CC2538 devices and their features, and use them to
define the linker script memory regions. The .nrdata output section is
now always defined in order to trigger an error if it is used but no
memory is available for it. The CC2538 device used by Contiki is made a
configuration option, the CC2538SF53 device being the default.

This makes more sense than defining the flash memory address and size as
configuration options like previously, all the more not all values are
possible and all the features are linked by each device.

This change also makes it possible to:
 - use the correct SRAM parameters for the CC2538NF11,
 - know at build time if the AES, SHA, ECC and RSA hardware features are
   available on the selected CC2538 device.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
This commit is contained in:
Benoît Thébaudeau 2015-06-18 22:31:53 +02:00
parent 513d8bc9d5
commit 790c253d6d
6 changed files with 165 additions and 70 deletions

View File

@ -110,7 +110,8 @@ CUSTOM_RULE_LINK=1
### This rule is used to generate the correct linker script
LDGENFLAGS += $(addprefix -D,$(subst $(COMMA), ,$(DEFINES)))
LDGENFLAGS += $(addprefix -I,$(SOURCEDIRS))
LDGENFLAGS += -imacros "contiki-conf.h"
LDGENFLAGS += -imacros "contiki-conf.h" -imacros "dev/cc2538-dev.h"
LDGENFLAGS += -imacros "dev/flash-cca.h"
LDGENFLAGS += -x c -P -E
# NB: Assumes LDSCRIPT was not overridden and is in $(OBJECTDIR)

View File

@ -33,40 +33,30 @@
* stage. Rather, it is used as input for the auto-generation of the actual
* ld script, which is called cc2538.ld and will be in the project directory
*/
#if (LPM_CONF_MAX_PM==2) && (LPM_CONF_ENABLE != 0)
#define NRSRAM_START 0x20000000
#define NRSRAM_LEN 0x00004000
#define SRAM_START 0x20004000
#define SRAM_LEN 0x00004000
#else
#define SRAM_START 0x20000000
#define SRAM_LEN 0x00008000
#endif
#ifdef FLASH_CONF_ORIGIN
#define FLASH_ORIGIN FLASH_CONF_ORIGIN
#else
#error FLASH_CONF_ORIGIN is not specified. Please define FLASH_CONF_ORIGIN in contiki-conf.h.
#endif
#ifdef FLASH_CONF_SIZE
#define FLASH_SIZE FLASH_CONF_SIZE
#else
#error FLASH_CONF_SIZE is not specified. Please define FLASH_CONF_SIZE in contiki-conf.h.
#endif
#define FLASH_CCA_LENGTH 44
#define FLASH_LENGTH (FLASH_SIZE - FLASH_CCA_LENGTH)
#define FLASH_CCA_ORIGIN (FLASH_ORIGIN + FLASH_LENGTH)
MEMORY
{
FLASH (rx) : ORIGIN = FLASH_ORIGIN, LENGTH = FLASH_LENGTH
FLASH_CCA (RX) : ORIGIN = FLASH_CCA_ORIGIN, LENGTH = FLASH_CCA_LENGTH
#if (LPM_CONF_MAX_PM==2) && (LPM_CONF_ENABLE != 0)
NRSRAM (RWX) : ORIGIN = NRSRAM_START, LENGTH = NRSRAM_LEN
FLASH_FW (rx) : ORIGIN = CC2538_DEV_FLASH_ADDR,
LENGTH = CC2538_DEV_FLASH_SIZE - FLASH_CCA_SIZE
FLASH_CCA (RX) : ORIGIN = FLASH_CCA_ADDR, LENGTH = FLASH_CCA_SIZE
/*
* If PM2 is enabled, then the PM2 SRAM limitations apply, i.e. the
* regular-leakage SRAM is a non-retention SRAM and the low-leakage SRAM is
* a full-retention SRAM.
* Else, the data in the regular-leakage SRAM is always retained, so there
* are virtually a non-retention SRAM with a size of 0 bytes and a
* full-retention SRAM spanning the whole SRAM, which is more convenient to
* use.
*/
#if LPM_CONF_ENABLE && LPM_CONF_MAX_PM >= 2
NRSRAM (RWX) : ORIGIN = CC2538_DEV_RLSRAM_ADDR,
LENGTH = CC2538_DEV_RLSRAM_SIZE
FRSRAM (RWX) : ORIGIN = CC2538_DEV_LLSRAM_ADDR,
LENGTH = CC2538_DEV_LLSRAM_SIZE
#else
NRSRAM (RWX) : ORIGIN = CC2538_DEV_RLSRAM_ADDR, LENGTH = 0
FRSRAM (RWX) : ORIGIN = CC2538_DEV_SRAM_ADDR, LENGTH = CC2538_DEV_SRAM_SIZE
#endif
SRAM (RWX) : ORIGIN = SRAM_START, LENGTH = SRAM_LEN
}
SECTIONS
@ -78,25 +68,25 @@ SECTIONS
*(.text*)
*(.rodata*)
_etext = .;
} > FLASH= 0
} > FLASH_FW= 0
.socdata (NOLOAD) :
{
*(.udma_channel_control_table)
} > SRAM
} > FRSRAM
.data : ALIGN(4)
{
_data = .;
*(.data*)
_edata = .;
} > SRAM AT > FLASH
} > FRSRAM AT > FLASH_FW
_ldata = LOADADDR(.data);
.ARM.exidx :
{
*(.ARM.exidx*)
} > FLASH
} > FLASH_FW
.bss :
{
@ -104,21 +94,19 @@ SECTIONS
*(.bss*)
*(COMMON)
_ebss = .;
} > SRAM
} > FRSRAM
.stack (NOLOAD) :
{
*(.stack)
} > SRAM
} > FRSRAM
#if (LPM_CONF_MAX_PM==2) && (LPM_CONF_ENABLE != 0)
.nrdata (NOLOAD) :
{
_nrdata = .;
*(.nrdata*)
_enrdata = .;
} > NRSRAM
#endif
.flashcca :
{

126
cpu/cc2538/dev/cc2538-dev.h Normal file
View File

@ -0,0 +1,126 @@
/*
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* 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-devices cc2538 family of devices
*
* Definitions for the cc2538 family of devices
* @{
*
* \file
* Header file for the cc2538 devices definitions
*/
#ifndef CC2538_DEV_H_
#define CC2538_DEV_H_
#include "contiki-conf.h"
#include "sys/cc.h"
/*----------------------------------------------------------------------------*/
/** \name Bit-fields for the CC2538 devices features
* @{
*/
#define CC2538_DEV_ID_M 0x0000000F /**< ID mask */
#define CC2538_DEV_ID_S 0 /**< ID shift */
#define CC2538_DEV_FLASH_SIZE_KB_M 0x0000FFF0 /**< kiB flash size mask */
#define CC2538_DEV_FLASH_SIZE_KB_S 4 /**< kiB flash size shift */
#define CC2538_DEV_SRAM_SIZE_KB_M 0x00FF0000 /**< kiB SRAM size mask */
#define CC2538_DEV_SRAM_SIZE_KB_S 16 /**< kiB SRAM size shift */
#define CC2538_DEV_AES_SHA_M 0x01000000 /**< Security HW AES/SHA */
#define CC2538_DEV_ECC_RSA_M 0x02000000 /**< Security HW ECC/RSA */
/** @} */
/*----------------------------------------------------------------------------*/
/** \name Macro defining a CC2538 device from its features
* @{
*/
#define CC2538_DEV_DEF(id, flash_size_kb, sram_size_kb, aes_sha, ecc_rsa) \
((id) << CC2538_DEV_ID_S | (flash_size_kb) << CC2538_DEV_FLASH_SIZE_KB_S | \
(sram_size_kb) << CC2538_DEV_SRAM_SIZE_KB_S | \
((aes_sha) ? CC2538_DEV_AES_SHA_M : 0) | \
((ecc_rsa) ? CC2538_DEV_ECC_RSA_M : 0))
/** @} */
/*----------------------------------------------------------------------------*/
/** \name Available CC2538 devices
* @{
*/
#define CC2538_DEV_CC2538SF53 CC2538_DEV_DEF(0, 512, 32, 1, 1)
#define CC2538_DEV_CC2538SF23 CC2538_DEV_DEF(1, 256, 32, 1, 1)
#define CC2538_DEV_CC2538NF53 CC2538_DEV_DEF(2, 512, 32, 1, 0)
#define CC2538_DEV_CC2538NF23 CC2538_DEV_DEF(3, 256, 32, 1, 0)
#define CC2538_DEV_CC2538NF11 CC2538_DEV_DEF(4, 128, 16, 1, 0)
/** @} */
/*----------------------------------------------------------------------------*/
/** \name CC2538 device used by Contiki
* @{
*/
#ifdef CC2538_DEV_CONF
#define CC2538_DEV CC2538_DEV_CONF
#else
#define CC2538_DEV CC2538_DEV_CC2538SF53
#endif
/** @} */
/*----------------------------------------------------------------------------*/
/** \name Features of the CC2538 device used by Contiki
* @{
*/
/** Flash address */
#define CC2538_DEV_FLASH_ADDR 0x00200000
/** Flash size in bytes */
#define CC2538_DEV_FLASH_SIZE (((CC2538_DEV & CC2538_DEV_FLASH_SIZE_KB_M) >> \
CC2538_DEV_FLASH_SIZE_KB_S) << 10)
/** SRAM (non-retention + low-leakage) address */
#define CC2538_DEV_SRAM_ADDR (CC2538_DEV_RLSRAM_SIZE ? \
CC2538_DEV_RLSRAM_ADDR : \
CC2538_DEV_LLSRAM_ADDR)
/** SRAM (non-retention + low-leakage) size in bytes */
#define CC2538_DEV_SRAM_SIZE (((CC2538_DEV & CC2538_DEV_SRAM_SIZE_KB_M) >> \
CC2538_DEV_SRAM_SIZE_KB_S) << 10)
/** Regular-leakage SRAM address */
#define CC2538_DEV_RLSRAM_ADDR 0x20000000
/** Regular-leakage SRAM size in bytes */
#define CC2538_DEV_RLSRAM_SIZE (CC2538_DEV_SRAM_SIZE - CC2538_DEV_LLSRAM_SIZE)
/** Low-leakage SRAM address */
#define CC2538_DEV_LLSRAM_ADDR 0x20004000
/** Low-leakage SRAM size in bytes */
#define CC2538_DEV_LLSRAM_SIZE MIN(CC2538_DEV_SRAM_SIZE, 16384)
/** Security HW AES/SHA */
#define CC2538_DEV_AES_SHA (!!(CC2538_DEV & CC2538_DEV_AES_SHA_M))
/** Security HW ECC/RSA */
#define CC2538_DEV_ECC_RSA (!!(CC2538_DEV & CC2538_DEV_ECC_RSA_M))
/** @} */
#endif /* CC2538_DEV_H_ */
/**
* @}
* @}
*/

View File

@ -48,8 +48,18 @@
#ifndef FLASH_CCA_H_
#define FLASH_CCA_H_
#include "dev/cc2538-dev.h"
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/** \name Flash lock bit page and CCA location
* @{
*/
#define FLASH_CCA_ADDR (CC2538_DEV_FLASH_ADDR + CC2538_DEV_FLASH_SIZE - \
FLASH_CCA_SIZE) /**< Address */
#define FLASH_CCA_SIZE 0x0000002C /**< Size in bytes */
/** @} */
/*---------------------------------------------------------------------------*/
/** \name Bootloader backdoor configuration bit fields
* @{
*/

View File

@ -57,21 +57,6 @@ typedef uint32_t rtimer_clock_t;
#define FLASH_CCA_CONF_BOOTLDR_BACKDOOR_ACTIVE_HIGH 0 /**< A logic low level activates the boot loader */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Flash Memory configuration
*
* @{
*/
#ifndef FLASH_CONF_ORIGIN
#define FLASH_CONF_ORIGIN 0x00200000
#endif
#ifndef FLASH_CONF_SIZE
#define FLASH_CONF_SIZE 0x00080000 /* 512 KiB */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Watchdog Timer configuration

View File

@ -57,21 +57,6 @@ typedef uint32_t rtimer_clock_t;
#define FLASH_CCA_CONF_BOOTLDR_BACKDOOR_ACTIVE_HIGH 0 /**< A logic low level activates the boot loader */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Flash Memory configuration
*
* @{
*/
#ifndef FLASH_CONF_ORIGIN
#define FLASH_CONF_ORIGIN 0x00200000
#endif
#ifndef FLASH_CONF_SIZE
#define FLASH_CONF_SIZE 0x00080000 /* 512 KiB */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Watchdog Timer configuration