Skip to content

Commit b001c07

Browse files
committed
Correct _etext location; clean up .ld files
1. Make _extext and _sidata coincide. Old _etext location did not include .ARM.exidx sections, which were usually absent but not always. So flash data was copied to RAM in wrong place. 2. Use decimal constants with "K" and "M" suffixes in .ld files instead of hex constants, to make them easier to read and check for accuracy.
1 parent 6be6df6 commit b001c07

14 files changed

Lines changed: 103 additions & 80 deletions

ports/atmel-samd/boards/samd21x18-bootloader-crystalless.ld

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
GNU linker script for SAMD21
2+
GNU linker script for SAMD21x18 (256K flash, 32K RAM)
33
*/
44

55
/* Specify the memory areas */
66
MEMORY
77
{
88
/* Leave 8KiB for the bootloader, 256b for persistent config (clock), 64k for the flash file system and 256b for the user config. */
9-
FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000 - 0x2000 - 0x100 - 0x010000 - 0x100
10-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */
9+
FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K - 256 - 64K - 256
10+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
1111
}
1212

1313
/* top end of the stack */
@@ -30,14 +30,14 @@ SECTIONS
3030
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
3131

3232
. = ALIGN(4);
33-
_etext = .; /* define a global symbol at end of code */
3433
} >FLASH
3534

3635
.ARM.exidx :
3736
{
3837
*(.ARM.exidx*)
3938
*(.gnu.linkonce.armexidx.*)
40-
_sidata = .; /* This is used by the startup in order to initialize the .data section */
39+
_etext = .; /* define a global symbol at end of code */
40+
_sidata = .; /* start of .data section */
4141
} > FLASH
4242

4343
/* This is the initialized data section
@@ -76,7 +76,7 @@ SECTIONS
7676
.stack :
7777
{
7878
. = ALIGN(4);
79-
. = . + 0x800; /* Reserve a minimum of 2K for the stack. */
79+
. = . + 2K; /* Reserve a minimum of 2K for the stack. */
8080
. = ALIGN(4);
8181
} >RAM
8282

ports/atmel-samd/boards/samd21x18-bootloader-external-flash-crystalless.ld

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
GNU linker script for SAMD21
2+
GNU linker script for SAMD21x18 (256K flash, 32K RAM)
33
*/
44

55
/* Specify the memory areas */
66
MEMORY
77
{
88
/* Leave 8KiB for the bootloader, 256b for internal config and 256b for user config. */
9-
FLASH (rx) : ORIGIN = 0x00000000 + 0x2000, LENGTH = 0x00040000 - 0x2000 - 0x100 - 0x100
10-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */
9+
FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K - 256 - 256
10+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
1111
}
1212

1313
/* top end of the stack */
@@ -30,14 +30,14 @@ SECTIONS
3030
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
3131

3232
. = ALIGN(4);
33-
_etext = .; /* define a global symbol at end of code */
3433
} >FLASH
3534

3635
.ARM.exidx :
3736
{
3837
*(.ARM.exidx*)
3938
*(.gnu.linkonce.armexidx.*)
40-
_sidata = .; /* This is used by the startup in order to initialize the .data section */
39+
_etext = .; /* define a global symbol at end of code */
40+
_sidata = .; /* start of .data section */
4141
} > FLASH
4242

4343
/* This is the initialized data section
@@ -76,7 +76,7 @@ SECTIONS
7676
.stack :
7777
{
7878
. = ALIGN(4);
79-
. = . + 0x800; /* Reserve a minimum of 2K for the stack. */
79+
. = . + 2K; /* Reserve a minimum of 2K for the stack. */
8080
. = ALIGN(4);
8181
} >RAM
8282

ports/atmel-samd/boards/samd21x18-bootloader-external-flash.ld

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
GNU linker script for SAMD21
2+
GNU linker script for SAMD21x18 (256K flash, 32K RAM)
33
*/
44

55
/* Specify the memory areas */
66
MEMORY
77
{
8-
FLASH (rx) : ORIGIN = 0x00000000 + 0x2000, LENGTH = 0x00040000 - 0x2000 - 0x100 /* Leave 8KiB for the bootloader and 256b for user config. */
9-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */
8+
/* Leave 8KiB for the bootloader and 256b for user config. */
9+
FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K - 256
10+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K /* 32 KiB RAM */
1011
}
1112

1213
/* top end of the stack */
@@ -29,21 +30,21 @@ SECTIONS
2930
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
3031

3132
. = ALIGN(4);
32-
_etext = .; /* define a global symbol at end of code */
3333
} >FLASH
3434

3535
.ARM.exidx :
3636
{
3737
*(.ARM.exidx*)
3838
*(.gnu.linkonce.armexidx.*)
39-
_sidata = .; /* This is used by the startup in order to initialize the .data section */
39+
_etext = .; /* define a global symbol at end of code */
40+
_sidata = .; /* start of .data section */
4041
} > FLASH
4142

4243
/* This is the initialized data section
4344
The program executes knowing that the data is in the RAM
4445
but the loader puts the initial values in the FLASH (inidata).
4546
It is one task of the startup to copy the initial values from FLASH to RAM. */
46-
.data : AT ( _sidata )
47+
.data : AT ( _etext )
4748
{
4849
. = ALIGN(4);
4950
_srelocate = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
@@ -75,7 +76,7 @@ SECTIONS
7576
.stack :
7677
{
7778
. = ALIGN(4);
78-
. = . + 0x800; /* Reserve a minimum of 2K for the stack. */
79+
. = . + 2K; /* Reserve a minimum of 2K for the stack. */
7980
. = ALIGN(4);
8081
} >RAM
8182

ports/atmel-samd/boards/samd21x18-bootloader.ld

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
GNU linker script for SAMD21
2+
GNU linker script for SAMD21x18 (256K flash, 32K RAM)
33
*/
44

55
/* Specify the memory areas */
66
MEMORY
77
{
88
/* Leave 8KiB for the bootloader, and 64k for the flash file system. */
9-
FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000 - 0x2000 - 0x010000
10-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */
9+
FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K - 64K
10+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
1111
}
1212

1313
/* top end of the stack */
@@ -30,14 +30,14 @@ SECTIONS
3030
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
3131

3232
. = ALIGN(4);
33-
_etext = .; /* define a global symbol at end of code */
3433
} >FLASH
3534

3635
.ARM.exidx :
3736
{
3837
*(.ARM.exidx*)
3938
*(.gnu.linkonce.armexidx.*)
40-
_sidata = .; /* This is used by the startup in order to initialize the .data section */
39+
_etext = .; /* define a global symbol at end of code */
40+
_sidata = .; /* start of .data section */
4141
} > FLASH
4242

4343
/* This is the initialized data section
@@ -76,7 +76,7 @@ SECTIONS
7676
.stack :
7777
{
7878
. = ALIGN(4);
79-
. = . + 0x800; /* Reserve a minimum of 2K for the stack. */
79+
. = . + 2K; /* Reserve a minimum of 2K for the stack. */
8080
. = ALIGN(4);
8181
} >RAM
8282

ports/atmel-samd/boards/samd21x18-external-flash.ld

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
GNU linker script for SAMD21
2+
GNU linker script for SAMD21x18 (256K flash, 32K RAM)
33
*/
44

55
/* Specify the memory areas */
66
MEMORY
77
{
88
/* 256 KiB but leave 256b for internal config and 256b for user config (protected eeprom) */
9-
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000 - 0x100 - 0x100
10-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */
9+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K - 256 - 256
10+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
1111
}
1212

1313
/* top end of the stack */
@@ -29,14 +29,14 @@ SECTIONS
2929
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
3030

3131
. = ALIGN(4);
32-
_etext = .; /* define a global symbol at end of code */
3332
} >FLASH
3433

3534
.ARM.exidx :
3635
{
3736
*(.ARM.exidx*)
3837
*(.gnu.linkonce.armexidx.*)
39-
_sidata = .; /* This is used by the startup in order to initialize the .data section */
38+
_etext = .; /* define a global symbol at end of code */
39+
_sidata = .; /* start of .data section */
4040
} > FLASH
4141

4242
/* This is the initialized data section
@@ -75,7 +75,7 @@ SECTIONS
7575
.stack :
7676
{
7777
. = ALIGN(4);
78-
. = . + 0x800; /* Reserve a minimum of 2K for the stack. */
78+
. = . + 2K; /* Reserve a minimum of 2K for the stack. */
7979
. = ALIGN(4);
8080
} >RAM
8181

ports/atmel-samd/boards/samd21x18.ld

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
GNU linker script for SAMD21
2+
GNU linker script for SAMD21x18 (256K flash, 32K RAM)
33
*/
44

55
/* Specify the memory areas */
66
MEMORY
77
{
88
/* Leave 256b for internal config, 64k for the flash file system and 256b for user config. */
9-
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000 - 0x100 - 0x010000
10-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */
9+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K - 256 - 64K
10+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
1111
}
1212

1313
/* top end of the stack */
@@ -29,11 +29,17 @@ SECTIONS
2929
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
3030

3131
. = ALIGN(4);
32-
_etext = .; /* define a global symbol at end of code */
33-
_sidata = _etext; /* This is used by the startup in order to initialize the .data section */
3432
} >FLASH
3533

36-
/* This is the initialized data section
34+
.ARM.exidx :
35+
{
36+
*(.ARM.exidx*)
37+
*(.gnu.linkonce.armexidx.*)
38+
_etext = .; /* define a global symbol at end of code */
39+
_sidata = .; /* start of .data section */
40+
} > FLASH
41+
42+
/* This is the initialized data section
3743
The program executes knowing that the data is in the RAM
3844
but the loader puts the initial values in the FLASH (inidata).
3945
It is one task of the startup to copy the initial values from FLASH to RAM. */
@@ -69,7 +75,7 @@ SECTIONS
6975
.stack :
7076
{
7177
. = ALIGN(4);
72-
. = . + 0x800; /* Reserve a minimum of 2K for the stack. */
78+
. = . + 2K; /* Reserve a minimum of 2K for the stack. */
7379
. = ALIGN(4);
7480
} >RAM
7581

ports/atmel-samd/boards/samd51x18-bootloader-external-flash.ld

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
GNU linker script for SAMD51
2+
GNU linker script for SAMD51x18 (256K flash, 128K RAM)
33
*/
44

55
/* Specify the memory areas */
66
MEMORY
77
{
8-
FLASH (rx) : ORIGIN = 0x00000000 + 0x4000, LENGTH = 0x00040000 - 0x4000 /* Leave 16KiB for the bootloader. */
9-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00020000 /* 128 KiB */
8+
/* Leave 16KiB for the bootloader. */
9+
FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 256K - 16K
10+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
1011
}
1112

1213
/* top end of the stack */
@@ -29,14 +30,14 @@ SECTIONS
2930
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
3031

3132
. = ALIGN(4);
32-
_etext = .; /* define a global symbol at end of code */
3333
} >FLASH
3434

3535
.ARM.exidx :
3636
{
3737
*(.ARM.exidx*)
3838
*(.gnu.linkonce.armexidx.*)
39-
_sidata = .; /* This is used by the startup in order to initialize the .data section */
39+
_etext = .; /* define a global symbol at end of code */
40+
_sidata = .; /* start of .data section */
4041
} > FLASH
4142

4243
/* This is the initialized data section
@@ -75,7 +76,7 @@ SECTIONS
7576
.stack :
7677
{
7778
. = ALIGN(4);
78-
. = . + 0x800; /* Reserve a minimum of 2K for the stack. */
79+
. = . + 2K; /* Reserve a minimum of 2K for the stack. */
7980
. = ALIGN(4);
8081
} >RAM
8182

ports/atmel-samd/boards/samd51x19-bootloader-external-flash.ld

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
GNU linker script for SAMD51
2+
GNU linker script for SAMD51x19 (512K flash, 192K RAM)
33
*/
44

55
/* Specify the memory areas */
66
MEMORY
77
{
8-
FLASH (rx) : ORIGIN = 0x00000000 + 0x4000, LENGTH = 0x00080000 - 0x4000 /* Leave 16KiB for the bootloader. */
9-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00030000 /* 192 KiB */
8+
/* Leave 16KiB for the bootloader. */
9+
FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 512K - 16K
10+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
1011
}
1112

1213
/* top end of the stack */
@@ -29,14 +30,14 @@ SECTIONS
2930
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
3031

3132
. = ALIGN(4);
32-
_etext = .; /* define a global symbol at end of code */
3333
} >FLASH
3434

3535
.ARM.exidx :
3636
{
3737
*(.ARM.exidx*)
3838
*(.gnu.linkonce.armexidx.*)
39-
_sidata = .; /* This is used by the startup in order to initialize the .data section */
39+
_etext = .; /* define a global symbol at end of code */
40+
_sidata = .; /* start of .data section */
4041
} > FLASH
4142

4243
/* This is the initialized data section
@@ -75,7 +76,7 @@ SECTIONS
7576
.stack :
7677
{
7778
. = ALIGN(4);
78-
. = . + 0x800; /* Reserve a minimum of 2K for the stack. */
79+
. = . + 2K; /* Reserve a minimum of 2K for the stack. */
7980
. = ALIGN(4);
8081
} >RAM
8182

ports/atmel-samd/boards/samd51x19-bootloader.ld

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
GNU linker script for SAMD51
2+
GNU linker script for SAMD51x19 (512K flash, 192K RAM)
33
*/
44

55
/* Specify the memory areas */
66
MEMORY
77
{
8-
FLASH (rx) : ORIGIN = 0x00000000 + 0x4000, LENGTH = 0x00080000 - 0x4000 - 0x00040000 /* Leave 16KiB for the bootloader and 256KiB for the internal file system. */
9-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00030000 /* 192 KiB */
8+
/* Leave 16KiB for the bootloader and 256KiB for the internal file system. */
9+
FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 512K - 16K - 256K
10+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
1011
}
1112

1213
/* top end of the stack */
@@ -29,14 +30,14 @@ SECTIONS
2930
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
3031

3132
. = ALIGN(4);
32-
_etext = .; /* define a global symbol at end of code */
3333
} >FLASH
3434

3535
.ARM.exidx :
3636
{
3737
*(.ARM.exidx*)
3838
*(.gnu.linkonce.armexidx.*)
39-
_sidata = .; /* This is used by the startup in order to initialize the .data section */
39+
_etext = .; /* define a global symbol at end of code */
40+
_sidata = .; /* start of .data section */
4041
} > FLASH
4142

4243
/* This is the initialized data section
@@ -75,7 +76,7 @@ SECTIONS
7576
.stack :
7677
{
7778
. = ALIGN(4);
78-
. = . + 0x800; /* Reserve a minimum of 2K for the stack. */
79+
. = . + 2K; /* Reserve a minimum of 2K for the stack. */
7980
. = ALIGN(4);
8081
} >RAM
8182

0 commit comments

Comments
 (0)