boards/stm32f103-minimum: fix unaligned pointer to .data section in ld.script #14762
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch fix _eronly value which is used during boot process to initialize .data section to sram.
Since .data section is 4 byte aligned in flash, also _eronly must follow this alignment to stay coherent with the start address of .data.
If one of the sections preceeding .data has a size which is not 4 byte aligned, the _eronly value does not match with .data physical address resulting in wrong copy of data section to sram and thus an almost immediate hardfault.
Summary
This is a bugfix in linkerscript of stm32f103-minimum board.
_eronly is wrongly set and this caused data section to be copied to sram with additional garbage padding.
This happens when, for example, the .text section size is not a multiple of 4bytes (.text preceeds .data in elf map)
Similar bug has been fixed in e7ed720
Impact
Currently this has no impact.
There might be other boards with the same exact problem and this seems to have originated in commit 2925c28 , when ALIGN(4) has been added to some sections.
Testing
Test setup:
Code to trigger the bug:
Please note that in the code snippet, msg[] might be increased or decreased in order to have an unaligned .text size
Result (BUG)
uart:
�ABC
gdb:
Thread #1 (Suspended : Signal : SIGINT:Interrupt)
stack_dump() at assert.c:182 0x800111c
dump_stackinfo() at assert.c:232 0x8001392
dump_stacks() at assert.c:329 0x8001392
dump_running_task() at assert.c:653 0x8001392
dump_assert_info() at assert.c:707 0x8001392
_assert() at assert.c:892 0x8001392
__assert() at lib_assert.c:38 0x8003fc6
irq_unexpected_isr() at irq_unexpectedisr.c:56 0x80010c4
arm_doirq() at arm_doirq.c:90 0x8000ba8
exception_common() at arm_exception.S:214 0x80008e8
$ arm-none-eabi-readelf -a nuttx
...
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0x08000000 0x08000000 0x0c3e7 0x0c3e7 R E 0x1000
LOAD 0x00e000 0x20000000 0x0800c3e8 0x001a0 0x00f28 RW 0x1000
...
1781: 0800c3e7 0 NOTYPE GLOBAL DEFAULT ABS _eronly
Note that _eronly is wrongly set to 0x0800c3e7 instead of 0x0800c3e8
Result (BUGFIX)
uart:
ABCDF
msg: as
NuttShell (NSH) NuttX-12.6.0-RC1
nsh>
arm-none-eabi-readelf -a nuttx
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0x08000000 0x08000000 0x0c3e7 0x0c3e7 R E 0x1000
LOAD 0x00e000 0x20000000 0x0800c3e8 0x001a0 0x00f28 RW 0x1000
1781: 0800c3e8 0 NOTYPE GLOBAL DEFAULT ABS _eronly