Skip to content

Commit e9b7412

Browse files
committed
ld: Reset linker '.' value after .ER_CODE_SRAM section
When processing the .ER_CODE_SRAM section, the location counter is set to the VMA of that section, so after processing the next section will use that VMA instead of the next available address in the FLASH region. Reset the location counter to the next available FLASH address after processing this section will ensure that any subsequent FLASH data is placed in the correct location. This test fails without this patch: $ west build -p -b lpcxpresso55s69/lpc55s69/cpu0/ns \ samples/synchronization -T sample.kernel.synchronization .../ld: address 0x14003e84 of bin/tfm_s.axf section `.ER_TFM_CODE' is not within region `FLASH' .../ld: address 0x14005c20 of bin/tfm_s.axf section `.TFM_UNPRIV_CODE' is not within region `FLASH' .../ld: bin/tfm_s.axf section `.TFM_PSA_ROT_LINKER_DATA' will not fit in region `FLASH' .../ld: address 0x14003e84 of bin/tfm_s.axf section `.ER_TFM_CODE' is not within region `FLASH' .../ld: address 0x14005c20 of bin/tfm_s.axf section `.TFM_UNPRIV_CODE' is not within region `FLASH' .../ld: ERROR: CMSE stub (.gnu.sgstubs section) too far (0x10008540) from destination (0x14003ee4) Note that the linker is generating addresses within the CODE_RAM memory region rather than the FLASH region. Signed-off-by: Keith Packard <[email protected]>
1 parent 8d8f341 commit e9b7412

File tree

6 files changed

+20
-0
lines changed

6 files changed

+20
-0
lines changed

platform/ext/common/gcc/tfm_common_s.ld.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ SECTIONS
192192
. = ALIGN(4); /* This alignment is needed to make the section size 4 bytes aligned */
193193
} > CODE_RAM AT > FLASH
194194

195+
/* Reset current position for subsequent sections */
196+
. = LOADADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);
197+
195198
ASSERT(S_RAM_CODE_START % 4 == 0, "S_RAM_CODE_START must be divisible by 4")
196199

197200
Image$$ER_CODE_SRAM$$RO$$Base = ADDR(.ER_CODE_SRAM);

platform/ext/common/gcc/tfm_isolation_s.ld.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ SECTIONS
337337
. = ALIGN(4); /* This alignment is needed to make the section size 4 bytes aligned */
338338
} > CODE_RAM AT > FLASH
339339

340+
/* Reset current position for subsequent sections */
341+
. = LOADADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);
342+
340343
ASSERT(S_RAM_CODE_START % 4 == 0, "S_RAM_CODE_START must be divisible by 4")
341344

342345
Image$$ER_CODE_SRAM$$RO$$Base = ADDR(.ER_CODE_SRAM);

platform/ext/common/llvm/tfm_isolation_s.ld.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ SECTIONS
303303
. = ALIGN(4); /* This alignment is needed to make the section size 4 bytes aligned */
304304
} > CODE_RAM AT > FLASH
305305

306+
/* Reset current position for subsequent sections */
307+
. = LOADADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);
308+
306309
ASSERT(S_RAM_CODE_START % 4 == 0, "S_RAM_CODE_START must be divisible by 4")
307310

308311
Image$$ER_CODE_SRAM$$RO$$Base = ADDR(.ER_CODE_SRAM);

platform/ext/target/arm/musca_b1/Device/Source/gcc/musca_bl2.ld

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ SECTIONS
5858
*libflash_drivers.o(.rodata*)
5959
. = ALIGN(4); /* This alignment is needed to make the section size 4 bytes aligned */
6060
} > CODE_RAM AT > FLASH
61+
62+
/* Reset current position for subsequent sections */
63+
. = LOADADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);
64+
6165
Image$$ER_CODE_SRAM$$Base = ADDR(.ER_CODE_SRAM);
6266
Image$$ER_CODE_SRAM$$Limit = ADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);
6367

platform/ext/target/arm/musca_b1/Device/Source/llvm/musca_bl2.ld

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ SECTIONS
5757
*libflash_drivers.o(.rodata*)
5858
. = ALIGN(4); /* This alignment is needed to make the section size 4 bytes aligned */
5959
} > CODE_RAM AT > FLASH
60+
61+
/* Reset current position for subsequent sections */
62+
. = LOADADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);
63+
6064
Image$$ER_CODE_SRAM$$Base = ADDR(.ER_CODE_SRAM);
6165
Image$$ER_CODE_SRAM$$Limit = ADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);
6266

platform/ext/target/rpi/rp2350/linker_s.ld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ SECTIONS
150150
. = ALIGN(4); /* This alignment is needed to make the section size 4 bytes aligned */
151151
} > CODE_RAM AT > FLASH
152152

153+
/* Reset current position for subsequent sections */
154+
. = LOADADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);
155+
153156
ASSERT(S_RAM_CODE_START % 4 == 0, "S_RAM_CODE_START must be divisible by 4")
154157

155158
Image$$ER_CODE_SRAM$$RO$$Base = ADDR(.ER_CODE_SRAM);

0 commit comments

Comments
 (0)