Skip to content

Commit 76a029e

Browse files
committed
[M2351] Support initializing multiple .data/.bss sections with GCC_ARM
1 parent db11eef commit 76a029e

File tree

2 files changed

+62
-21
lines changed

2 files changed

+62
-21
lines changed

targets/TARGET_NUVOTON/TARGET_M2351/device/TOOLCHAIN_GCC_ARM/M2351.ld

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ SECTIONS
150150
. = ALIGN(8);
151151
} > VECTORS
152152

153+
.copy.table : ALIGN(4)
154+
{
155+
__copy_table_start__ = .;
156+
LONG (LOADADDR(.data))
157+
LONG (ADDR(.data))
158+
LONG (SIZEOF(.data))
159+
__copy_table_end__ = .;
160+
} > FLASH
161+
162+
.zero.table : ALIGN(4)
163+
{
164+
__zero_table_start__ = .;
165+
LONG (ADDR(.bss))
166+
LONG (SIZEOF(.bss))
167+
__zero_table_end__ = .;
168+
} > FLASH
169+
153170
.text :
154171
{
155172
*(.text*)

targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ extern void __main(void);
5555
void __iar_program_start(void);
5656
#elif defined(__GNUC__)
5757
extern uint32_t __StackTop;
58-
extern uint32_t __etext;
59-
extern uint32_t __data_start__;
60-
extern uint32_t __data_end__;
61-
extern uint32_t __bss_start__;
62-
extern uint32_t __bss_end__;
58+
extern uint32_t __copy_table_start__;
59+
extern uint32_t __copy_table_end__;
60+
extern uint32_t __zero_table_start__;
61+
extern uint32_t __zero_table_end__;
6362

6463
#if defined(TOOLCHAIN_GCC_ARM)
6564
extern void _start(void);
@@ -350,26 +349,51 @@ void Reset_Handler(void)
350349
__iar_program_start();
351350

352351
#elif defined(__GNUC__)
353-
uint32_t *src_ind = (uint32_t *) &__etext;
354-
uint32_t *dst_ind = (uint32_t *) &__data_start__;
355-
uint32_t *dst_end = (uint32_t *) &__data_end__;
356-
357-
/* Move .data section from ROM to RAM */
358-
if (src_ind != dst_ind) {
359-
for (; dst_ind < dst_end;) {
360-
*dst_ind ++ = *src_ind ++;
352+
/* Move (multiple) .data section(s) from ROM to RAM */
353+
{
354+
/* Struct of copy table entry which must match linker script */
355+
typedef struct copy_table_entry_ {
356+
uint32_t src; // Address to copy from
357+
uint32_t dst; // Address to copy to
358+
uint32_t size; // Copy size in bytes
359+
} copy_table_entry;
360+
361+
copy_table_entry *copy_table_ind = (copy_table_entry *) &__copy_table_start__;
362+
copy_table_entry *copy_table_end = (copy_table_entry *) &__copy_table_end__;
363+
364+
for (; copy_table_ind != copy_table_end; copy_table_ind ++) {
365+
uint32_t *src_ind = (uint32_t *) copy_table_ind->src;
366+
uint32_t *src_end = (uint32_t *) (copy_table_ind->src + copy_table_ind->size);
367+
uint32_t *dst_ind = (uint32_t *) copy_table_ind->dst;
368+
if (src_ind != dst_ind) {
369+
for (; src_ind < src_end;) {
370+
*dst_ind ++ = *src_ind ++;
371+
}
372+
}
361373
}
362374
}
363-
364-
/* Initialize .bss section to zero */
365-
dst_ind = (uint32_t *) &__bss_start__;
366-
dst_end = (uint32_t *) &__bss_end__;
367-
if (dst_ind != dst_end) {
368-
for (; dst_ind < dst_end;) {
369-
*dst_ind ++ = 0;
375+
376+
/* Initialize (multiple) .bss sections to zero */
377+
{
378+
/* Struct of zero table entry which must match linker script */
379+
typedef struct zero_table_entry_ {
380+
uint32_t start; // Address to start zero'ing
381+
uint32_t size; // Zero size in bytes
382+
} zero_table_entry;
383+
384+
zero_table_entry *zero_table_ind = (zero_table_entry *) &__zero_table_start__;
385+
zero_table_entry *zero_table_end = (zero_table_entry *) &__zero_table_end__;
386+
387+
for (; zero_table_ind != zero_table_end; zero_table_ind ++) {
388+
uint32_t *dst_ind = (uint32_t *) zero_table_ind->start;
389+
uint32_t *dst_end = (uint32_t *) (zero_table_ind->start + zero_table_ind->size);
390+
391+
for (; dst_ind < dst_end; ) {
392+
*dst_ind ++ = 0;
393+
}
370394
}
371395
}
372-
396+
373397
_start();
374398

375399
#endif

0 commit comments

Comments
 (0)