mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-05 09:29:39 +00:00
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:
parent
a191fcdb84
commit
96dd24836c
@ -64,7 +64,7 @@ SECTIONS
|
|||||||
.text :
|
.text :
|
||||||
{
|
{
|
||||||
_text = .;
|
_text = .;
|
||||||
KEEP(*(.vectors))
|
*(.vectors)
|
||||||
*(.text*)
|
*(.text*)
|
||||||
*(.rodata*)
|
*(.rodata*)
|
||||||
_etext = .;
|
_etext = .;
|
||||||
|
@ -54,7 +54,8 @@
|
|||||||
#ifdef NVIC_CONF_VTABLE_ADDRESS
|
#ifdef NVIC_CONF_VTABLE_ADDRESS
|
||||||
#define NVIC_VTABLE_ADDRESS NVIC_CONF_VTABLE_ADDRESS
|
#define NVIC_VTABLE_ADDRESS NVIC_CONF_VTABLE_ADDRESS
|
||||||
#else
|
#else
|
||||||
#define NVIC_VTABLE_ADDRESS 0x200000
|
extern void(*const vectors[])(void);
|
||||||
|
#define NVIC_VTABLE_ADDRESS ((uint32_t)&vectors)
|
||||||
#endif
|
#endif
|
||||||
/** @} */
|
/** @} */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -94,22 +94,7 @@ void pka_isr(void);
|
|||||||
/* Allocate stack space */
|
/* Allocate stack space */
|
||||||
static unsigned long stack[512] __attribute__ ((section(".stack")));
|
static unsigned long stack[512] __attribute__ ((section(".stack")));
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Linker construct indicating .text section location */
|
__attribute__((__section__(".vectors")))
|
||||||
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))
|
|
||||||
void(*const vectors[])(void) =
|
void(*const vectors[])(void) =
|
||||||
{
|
{
|
||||||
(void (*)(void))((unsigned long)stack + sizeof(stack)), /* Stack pointer */
|
(void (*)(void))((unsigned long)stack + sizeof(stack)), /* Stack pointer */
|
||||||
@ -277,6 +262,18 @@ void(*const vectors[])(void) =
|
|||||||
default_handler, /* 162 MACTimer */
|
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 */
|
/* Linker constructs indicating .data and .bss segment locations */
|
||||||
extern uint8_t _ldata;
|
extern uint8_t _ldata;
|
||||||
extern uint8_t _data;
|
extern uint8_t _data;
|
||||||
|
Loading…
Reference in New Issue
Block a user