From 0d260f61a019c6d2b133727315bca758c6bdfe74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Sun, 17 May 2015 21:07:10 +0200 Subject: [PATCH] cc2538: Fix .data LMA/VMA mismatch with some toolchains MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some toolchains, like Sourcery CodeBench Lite 2013.05-23 arm-none-eabi (http://sourcery.mentor.com/public/gnu_toolchain/arm-none-eabi/) automatically force the alignment of an output section LMA to use the maximum alignment of all its input sections. This toolchain uses GNU binutils 2.23, and this automatic behavior is the same as the manual behavior of the ALIGN_WITH_INPUT feature of GNU binutils 2.24+. This behavior is not an issue per se, but it creates a gap between _etext and the LMA of the .data output section if _etext does not have the same alignment, while reset_handler() initialized this section by copying the data from _etext to its VMA, hence an offset in the addresses of loaded data, and missing data. This commit fixes this issue by making reset_handler() directly use the LMA of the .data section using LOADADDR(.data), rather than assuming that _etext is this LMA. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/cc2538.lds | 1 + cpu/cc2538/startup-gcc.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cpu/cc2538/cc2538.lds b/cpu/cc2538/cc2538.lds index 17b048778..0ca3a2550 100644 --- a/cpu/cc2538/cc2538.lds +++ b/cpu/cc2538/cc2538.lds @@ -91,6 +91,7 @@ SECTIONS *(.data*) _edata = .; } > SRAM AT > FLASH + _ldata = LOADADDR(.data); .ARM.exidx : { diff --git a/cpu/cc2538/startup-gcc.c b/cpu/cc2538/startup-gcc.c index 99a624a7d..b72701505 100644 --- a/cpu/cc2538/startup-gcc.c +++ b/cpu/cc2538/startup-gcc.c @@ -275,7 +275,7 @@ void(*const vectors[])(void) = }; /*---------------------------------------------------------------------------*/ /* Linker constructs indicating .data and .bss segment locations */ -extern unsigned long _etext; +extern unsigned long _ldata; extern unsigned long _data; extern unsigned long _edata; extern unsigned long _bss; @@ -303,7 +303,7 @@ reset_handler(void) REG(SYS_CTRL_EMUOVR) = 0xFF; /* Copy the data segment initializers from flash to SRAM. */ - pul_src = &_etext; + pul_src = &_ldata; for(pul_dst = &_data; pul_dst < &_edata;) { *pul_dst++ = *pul_src++;