Skip to content

Commit

Permalink
cc2538: Fix .data LMA/VMA mismatch with some toolchains
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bthebaudeau committed May 23, 2015
1 parent 630b7f8 commit 0d260f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions cpu/cc2538/cc2538.lds
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ SECTIONS
*(.data*)
_edata = .;
} > SRAM AT > FLASH
_ldata = LOADADDR(.data);

.ARM.exidx :
{
Expand Down
4 changes: 2 additions & 2 deletions cpu/cc2538/startup-gcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand Down

0 comments on commit 0d260f6

Please sign in to comment.