From ab9abf2f51b7228b0c96cda5e8c3676bc41df3d1 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Fri, 6 Nov 2020 10:56:26 +0100 Subject: [PATCH] cpu/cc2538: add riotboot Flash Customer Configuration Area (CCA) is never written when the riotboot module is used. This required a riot application to have been previously flashed. riotboot will completely ignore this section, neither writing or erasing it. Slot flashing is currenly only supported with Jlink. Co-authored-by: Brenton Chetty --- cpu/cc2538/Kconfig | 3 +- cpu/cc2538/Makefile.features | 1 + cpu/cc2538/Makefile.include | 28 +++++++++++-- cpu/cc2538/include/cpu_conf.h | 3 +- .../ldscripts/{cc2538sf53.ld => cc2538.ld} | 8 +++- cpu/cc2538/ldscripts/cc2538nf11.ld | 39 ------------------ cpu/cc2538/ldscripts/cc2538nf23.ld | 40 ------------------- cpu/cc2538/ldscripts/cc2538nf53.ld | 40 ------------------- 8 files changed, 35 insertions(+), 127 deletions(-) rename cpu/cc2538/ldscripts/{cc2538sf53.ld => cc2538.ld} (67%) delete mode 100644 cpu/cc2538/ldscripts/cc2538nf11.ld delete mode 100644 cpu/cc2538/ldscripts/cc2538nf23.ld delete mode 100644 cpu/cc2538/ldscripts/cc2538nf53.ld diff --git a/cpu/cc2538/Kconfig b/cpu/cc2538/Kconfig index 5b1491e3ff..59aaf6c789 100644 --- a/cpu/cc2538/Kconfig +++ b/cpu/cc2538/Kconfig @@ -8,6 +8,7 @@ config CPU_FAM_CC2538 bool select CPU_CORE_CORTEX_M3 + select HAS_CORTEXM_MPU select HAS_CPU_CC2538 select HAS_PERIPH_CPUID select HAS_PERIPH_FLASHPAGE @@ -17,7 +18,7 @@ config CPU_FAM_CC2538 select HAS_PERIPH_HWRNG select HAS_PERIPH_UART_MODECFG select HAS_PERIPH_WDT - select HAS_CORTEXM_MPU + select HAS_RIOTBOOT ## CPU Models config CPU_MODEL_CC2538NF53 diff --git a/cpu/cc2538/Makefile.features b/cpu/cc2538/Makefile.features index 2b6665241f..50dedb106f 100644 --- a/cpu/cc2538/Makefile.features +++ b/cpu/cc2538/Makefile.features @@ -10,5 +10,6 @@ FEATURES_PROVIDED += periph_uart_modecfg FEATURES_PROVIDED += periph_wdt FEATURES_PROVIDED += cortexm_mpu +FEATURES_PROVIDED += riotboot include $(RIOTCPU)/cortexm_common/Makefile.features diff --git a/cpu/cc2538/Makefile.include b/cpu/cc2538/Makefile.include index 5c22f7a64d..9cf20fdaee 100644 --- a/cpu/cc2538/Makefile.include +++ b/cpu/cc2538/Makefile.include @@ -1,4 +1,7 @@ +# Strip 'K' from ROM_LEN definition +_rom_len_k = $(shell echo $1 | sed 's/K//') + # Set ROM and RAM lengths according to CPU model ifneq (,$(filter cc2538nf11,$(CPU_MODEL))) ROM_LEN ?= 128K @@ -13,14 +16,31 @@ ifneq (,$(filter cc2538nf53 cc2538sf53,$(CPU_MODEL))) RAM_LEN ?= 32K endif +# If using riotboot subtract 2 pages (2 * 2K) to not write over CCA +# section and keep page parity (so slots are split evenly among pages) +ifneq (,$(filter riotboot,$(FEATURES_USED))) + ROM_LEN := $(shell echo $$(( $(call _rom_len_k,$(ROM_LEN)) - 4 )) )K +endif + +# Set ROM and RAM start address ROM_START_ADDR ?= 0x00200000 RAM_START_ADDR ?= 0x20000000 -KB := 1024 -ROM_LEN_K := $(shell echo $(ROM_LEN) | sed 's/K//') -FLASHSIZE := $(shell echo $$(( $(ROM_LEN_K) * $(KB) )) ) - # Set CFLAGS +KB := 1024 +FLASHSIZE := $(shell echo $$(( $(call _rom_len_k,$(ROM_LEN)) * $(KB))) ) CFLAGS += -DCC2538_FLASHSIZE=$(FLASHSIZE)U +# Use common ld script +LINKER_SCRIPT ?= cc2538.ld + +# The entry point `cortex_vector_base` is defined in the cca field. +# If the cca field is updated when flashing a slot then the entry +# point will never be the bootloader but the respective slot. This +# ensures it never happens, the last page will never be touched when +# using riotboot. +ifneq (,$(filter riotboot,$(FEATURES_USED))) + CFLAGS += -DUPDATE_CCA=0 +endif + include $(RIOTMAKE)/arch/cortexm.inc.mk diff --git a/cpu/cc2538/include/cpu_conf.h b/cpu/cc2538/include/cpu_conf.h index 48af9a8b97..8e61f9875b 100644 --- a/cpu/cc2538/include/cpu_conf.h +++ b/cpu/cc2538/include/cpu_conf.h @@ -19,6 +19,7 @@ #ifndef CPU_CONF_H #define CPU_CONF_H +#include "kernel_defines.h" #include "cpu_conf_common.h" #include "cc2538.h" #include "cc2538_gpio.h" @@ -56,7 +57,7 @@ extern "C" { #ifndef FLASHPAGE_CC2538_USE_CCA_PAGE #define FLASHPAGE_CC2538_USE_CCA_PAGE (0) #endif -#if FLASHPAGE_CC2538_USE_CCA_PAGE +#if (IS_ACTIVE(MODULE_RIOTBOOT) || FLASHPAGE_CC2538_USE_CCA_PAGE) #define FLASHPAGE_NUMOF ((CC2538_FLASHSIZE / FLASHPAGE_SIZE)) #else #define FLASHPAGE_NUMOF ((CC2538_FLASHSIZE / FLASHPAGE_SIZE) -1) diff --git a/cpu/cc2538/ldscripts/cc2538sf53.ld b/cpu/cc2538/ldscripts/cc2538.ld similarity index 67% rename from cpu/cc2538/ldscripts/cc2538sf53.ld rename to cpu/cc2538/ldscripts/cc2538.ld index 34d1100189..dce01e4497 100644 --- a/cpu/cc2538/ldscripts/cc2538sf53.ld +++ b/cpu/cc2538/ldscripts/cc2538.ld @@ -16,12 +16,16 @@ * @author Hauke Petersen */ +INCLUDE cortexm_rom_offset.ld + /* Memory Space Definitions: */ MEMORY { - rom (rx) : ORIGIN = 0x00200000, LENGTH = 512K - 44 + rom (rx) : ORIGIN = _rom_start_addr + _rom_offset, LENGTH = _fw_rom_length cca : ORIGIN = 0x0027ffd4, LENGTH = 44 - ram (w!rx) : ORIGIN = 0x20000000, LENGTH = 32K + sram0 : ORIGIN = 0x20000000, LENGTH = 16K /* Lost in PM2 and PM3 */ + sram1 : ORIGIN = 0x20004000, LENGTH = 16K + ram (w!rx) : ORIGIN = _ram_start_addr, LENGTH = _ram_length } /* MCU Specific Section Definitions */ diff --git a/cpu/cc2538/ldscripts/cc2538nf11.ld b/cpu/cc2538/ldscripts/cc2538nf11.ld deleted file mode 100644 index a6574c8ee4..0000000000 --- a/cpu/cc2538/ldscripts/cc2538nf11.ld +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2014 Loci Controls Inc. - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @addtogroup cpu_cc2538 - * @{ - * - * @file - * @brief Linker script for the CC2538NF11 model MCU - * - * @author Ian Martin - */ - -/* Memory Space Definitions: */ -MEMORY -{ - rom (rx) : ORIGIN = 0x00200000, LENGTH = 128K - 44 - cca : ORIGIN = 0x0027ffd4, LENGTH = 44 - sram1 : ORIGIN = 0x20004000, LENGTH = 16K - ram (w!rx) : ORIGIN = 0x20004000, LENGTH = 16K -} - -/* MCU Specific Section Definitions */ -SECTIONS -{ - .flashcca : - { - KEEP(*(.flashcca)) - } > cca -} - -INCLUDE cortexm_base.ld - -/* @} */ diff --git a/cpu/cc2538/ldscripts/cc2538nf23.ld b/cpu/cc2538/ldscripts/cc2538nf23.ld deleted file mode 100644 index bf0657b6ec..0000000000 --- a/cpu/cc2538/ldscripts/cc2538nf23.ld +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2014 Loci Controls Inc. - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @addtogroup cpu_cc2538 - * @{ - * - * @file - * @brief Linker script for the CC2538NF23 and CC2538SF23 model MCUs - * - * @author Ian Martin - */ - -/* Memory Space Definitions: */ -MEMORY -{ - rom (rx) : ORIGIN = 0x00200000, LENGTH = 256K - 44 - cca : ORIGIN = 0x0027ffd4, LENGTH = 44 - sram0 : ORIGIN = 0x20000000, LENGTH = 16K /* Lost in PM2 and PM3 */ - sram1 : ORIGIN = 0x20004000, LENGTH = 16K - ram (w!rx) : ORIGIN = 0x20000000, LENGTH = 32K -} - -/* MCU Specific Section Definitions */ -SECTIONS -{ - .flashcca : - { - KEEP(*(.flashcca)) - } > cca -} - -INCLUDE cortexm_base.ld - -/* @} */ diff --git a/cpu/cc2538/ldscripts/cc2538nf53.ld b/cpu/cc2538/ldscripts/cc2538nf53.ld deleted file mode 100644 index d3840f64b8..0000000000 --- a/cpu/cc2538/ldscripts/cc2538nf53.ld +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2014 Loci Controls Inc. - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @addtogroup cpu_cc2538 - * @{ - * - * @file - * @brief Linker script for the CC2538NF53 and CC2538SF53 model MCUs - * - * @author Ian Martin - */ - -/* Memory Space Definitions: */ -MEMORY -{ - rom (rx) : ORIGIN = 0x00200000, LENGTH = 512K - 44 - cca : ORIGIN = 0x0027ffd4, LENGTH = 44 - sram0 : ORIGIN = 0x20000000, LENGTH = 16K /* Lost in PM2 and PM3 */ - sram1 : ORIGIN = 0x20004000, LENGTH = 16K - ram (w!rx) : ORIGIN = 0x20000000, LENGTH = 32K -} - -/* MCU Specific Section Definitions */ -SECTIONS -{ - .flashcca : - { - KEEP(*(.flashcca)) - } > cca -} - -INCLUDE cortexm_base.ld - -/* @} */