cc2538: Use &vectors instead of flash/.text start address

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 <benoit.thebaudeau.dev@gmail.com>
This commit is contained in:
Benoît Thébaudeau 2015-07-01 22:15:53 +02:00
parent a191fcdb84
commit 96dd24836c
3 changed files with 16 additions and 18 deletions

View file

@ -64,7 +64,7 @@ SECTIONS
.text :
{
_text = .;
KEEP(*(.vectors))
*(.vectors)
*(.text*)
*(.rodata*)
_etext = .;

View file

@ -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
/** @} */
/*---------------------------------------------------------------------------*/

View file

@ -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;