From 96dd24836c1057264a20f88c6b1de6b9db7304e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Wed, 1 Jul 2015 22:15:53 +0200 Subject: [PATCH] cc2538: Use &vectors instead of flash/.text start address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current CC2538 linker script in Contiki places the vector table at the beginning of the flash memory / .text output section. However, this location is arbitrary (the only requirement is that the vector table is 512-byte aligned), and custom linker scripts may be used with Contiki, which means that Contiki may be used with a vector table placed elsewhere. Thus, using the flash/.text start address in the CCA and as the default NVIC VTABLE value was wrong. This commit rather uses the address of the vectors[] array from startup-gcc.c, which makes it possible to freely move around the vector table without breaking anything or having to use a custom startup-gcc.c and to configure the NVIC driver for that. Moreover, referencing the vectors[] array naturally prevents it and its input section from being garbage-collected by the linker, so this commit also removes the now-unneeded "used" and "KEEP" keywords from the vector table. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/cc2538.lds | 2 +- cpu/cc2538/dev/nvic.h | 3 ++- cpu/cc2538/startup-gcc.c | 29 +++++++++++++---------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/cpu/cc2538/cc2538.lds b/cpu/cc2538/cc2538.lds index a2dd0d209..60a37c796 100644 --- a/cpu/cc2538/cc2538.lds +++ b/cpu/cc2538/cc2538.lds @@ -64,7 +64,7 @@ SECTIONS .text : { _text = .; - KEEP(*(.vectors)) + *(.vectors) *(.text*) *(.rodata*) _etext = .; diff --git a/cpu/cc2538/dev/nvic.h b/cpu/cc2538/dev/nvic.h index 6c7563680..8f2f68259 100644 --- a/cpu/cc2538/dev/nvic.h +++ b/cpu/cc2538/dev/nvic.h @@ -54,7 +54,8 @@ #ifdef NVIC_CONF_VTABLE_ADDRESS #define NVIC_VTABLE_ADDRESS NVIC_CONF_VTABLE_ADDRESS #else -#define NVIC_VTABLE_ADDRESS 0x200000 +extern void(*const vectors[])(void); +#define NVIC_VTABLE_ADDRESS ((uint32_t)&vectors) #endif /** @} */ /*---------------------------------------------------------------------------*/ diff --git a/cpu/cc2538/startup-gcc.c b/cpu/cc2538/startup-gcc.c index 35c2329d2..d3d6ec401 100644 --- a/cpu/cc2538/startup-gcc.c +++ b/cpu/cc2538/startup-gcc.c @@ -94,22 +94,7 @@ void pka_isr(void); /* Allocate stack space */ static unsigned long stack[512] __attribute__ ((section(".stack"))); /*---------------------------------------------------------------------------*/ -/* Linker construct indicating .text section location */ -extern uint8_t _text[0]; -/*---------------------------------------------------------------------------*/ -__attribute__ ((section(".flashcca"), used)) -const flash_cca_lock_page_t __cca = { - FLASH_CCA_BOOTLDR_CFG, /* Boot loader backdoor configuration */ - 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)) +__attribute__((__section__(".vectors"))) void(*const vectors[])(void) = { (void (*)(void))((unsigned long)stack + sizeof(stack)), /* Stack pointer */ @@ -277,6 +262,18 @@ void(*const vectors[])(void) = default_handler, /* 162 MACTimer */ }; /*---------------------------------------------------------------------------*/ +__attribute__((__section__(".flashcca"), __used__)) +const flash_cca_lock_page_t flash_cca_lock_page = { + FLASH_CCA_BOOTLDR_CFG, /* Boot loader backdoor configuration */ + FLASH_CCA_IMAGE_VALID, /* Image valid */ + &vectors, /* Vector table */ + /* 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 } +}; +/*---------------------------------------------------------------------------*/ /* Linker constructs indicating .data and .bss segment locations */ extern uint8_t _ldata; extern uint8_t _data;