@@ -6,7 +6,7 @@ Boards can setup reserved flash with _ld_reserved_flash_size in board.ld. */
66
77ENTRY (Reset_Handler)
88
9- code_size = 1M;
9+ code_size = _ld_flash_size >= 4M ? 2M : 1M;
1010_ld_default_stack_size = 20K;
1111
1212/* Default reserved flash to nothing. */
2222 FLASH_IVT (rx) : ORIGIN = 0x60001000 , LENGTH = 4K
2323 /* Place the ISRs 48k in to leave room for the bootloader when it is available. */
2424 FLASH_FIRMWARE (rx) : ORIGIN = 0x6000C000 , LENGTH = code_size - 48K
25- FLASH_FATFS (r) : ORIGIN = 0x60100000 , LENGTH = _ld_flash_size - code_size - _ld_reserved_flash_size
25+ FLASH_FATFS (r) : ORIGIN = 0x60000000 + code_size , LENGTH = _ld_flash_size - code_size - _ld_reserved_flash_size
2626 /* Teensy uses the last bit of flash for recovery. */
27- RESERVED_FLASH : ORIGIN = 0x60100000 + _ld_flash_size - _ld_reserved_flash_size, LENGTH = _ld_reserved_flash_size
27+ RESERVED_FLASH : ORIGIN = 0x60000000 + code_size + _ld_flash_size - _ld_reserved_flash_size, LENGTH = _ld_reserved_flash_size
2828 OCRAM (rwx) : ORIGIN = 0x20200000 , LENGTH = ram_size - 64K
2929 DTCM (x) : ORIGIN = 0x20000000 , LENGTH = 32K
3030 ITCM (x) : ORIGIN = 0x00000000 , LENGTH = 32K
@@ -52,24 +52,59 @@ SECTIONS
5252 . = ALIGN (4 );
5353 } > FLASH_IVT
5454
55- .text :
55+ /* Align for 256 ISR entries and place first in flash. Otherwise the UF2
56+ bootloader can't find it because it uses its own flash_config and ivt. */
57+ .isr_vector : ALIGN (4 * 256 )
5658 {
5759 . = ALIGN (4 );
58- __VECTOR_TABLE = .;
59- __VECTOR_RAM = .;
60- _ld_isr_table = .;
61-
6260 KEEP (*(.isr_vector )) /* Startup code */
61+ . = ALIGN (4 );
62+ } > ITCM AT> FLASH_FIRMWARE
63+ _ld_isr_destination = ADDR (.isr_vector );
64+ _ld_isr_flash_copy = LOADADDR (.isr_vector );
65+ _ld_isr_size = SIZEOF (.isr_vector );
66+ /* Used by the bootloader to start user code. */
67+ __VECTOR_TABLE = LOADADDR (.isr_vector );
68+
69+ .text :
70+ {
71+ . = ALIGN (4 );
6372 *(EXCLUDE_FILE (
6473 *fsl_flexspi.o
74+ *dcd_ci_hs.o
75+ *tusb_fifo.o
76+ *usbd.o
77+ *string0.o
78+ *py/nlr*.o
79+ *py/obj.o
80+ *py/gc.o
81+ *py/map.o
82+ *py/runtime.o
83+ *py/objboundmeth.o
84+ *py/objtype.o
6585 ) .text *) /* .text* sections (code) */
66- *(.rodata *) /* .rodata* sections (constants, strings, etc.) */
86+
87+ /* Keep USB processing functions out of RAM because we don't know which will be used.
88+ We try to only keep USB interrupt related functions. */
89+ *dcd_ci_hs.o (.text .process_ *_request .text .dcd_edpt * .text .dcd_init .text .dcd_set_address )
90+ *usbd.o (.text .process_ *_request .text .process_ [gs]et* .text .tud_ * .text .usbd_ * .text .configuration_reset .text .invoke_ *)
91+
92+ /* Anything marked cold/unlikely should be in flash. */
93+ *(.text .unlikely .*)
94+
95+ *(EXCLUDE_FILE (
96+ *dcd_ci_hs.o
97+ *py/objboundmeth.o
98+ *py/objtype.o
99+ ) .rodata *) /* .rodata* sections (constants, strings, etc.) */
67100 . = ALIGN (4 );
68101 } > FLASH_FIRMWARE
69102
70103 .ARM.exidx :
71104 {
105+ __exidx_start = .;
72106 *(.ARM .exidx *)
107+ __exidx_end = .;
73108 *(.gnu .linkonce .armexidx .*)
74109 _etext = .; /* define a global symbol at end of code */
75110 __etext = .; /* define a global symbol at end of code */
@@ -81,7 +116,6 @@ SECTIONS
81116 {
82117 . = ALIGN (4 );
83118 *(.data *) /* .data* sections */
84- *fsl_flexspi.o (.text *)
85119 . = ALIGN (4 );
86120 } > OCRAM AT> FLASH_FIRMWARE
87121 _ld_ocram_data_destination = ADDR (.data );
@@ -93,7 +127,7 @@ SECTIONS
93127 {
94128 . = ALIGN (4 );
95129
96- *(.bss *)
130+ *(SORT_BY_ALIGNMENT ( SORT_BY_NAME ( .bss *)) )
97131 *(COMMON)
98132
99133 . = ALIGN (4 );
@@ -103,11 +137,23 @@ SECTIONS
103137 _ld_heap_start = _ld_ocram_bss_start + _ld_ocram_bss_size;
104138 _ld_heap_end = ORIGIN (OCRAM) + LENGTH (OCRAM);
105139
106- .itcm :
140+
141+ .itcm : ALIGN (4 )
107142 {
108143 . = ALIGN (4 );
109144 *(.itcm .*)
110-
145+ *fsl_flexspi.o (.text *)
146+ *dcd_ci_hs.o (.text *)
147+ *tusb_fifo.o (.text *)
148+ *py/objboundmeth.o (.text *)
149+ *py/objtype.o (.text *)
150+ *py/obj.o (.text *)
151+ *py/gc.o (.text *)
152+ *py/map.o (.text *)
153+ *py/nlr*.o (.text *)
154+ *py/runtime.o (.text *)
155+ *(.text .process_ *_isr .text .dcd_event_ * .text .osal_queue *)
156+ *string0.o (.text *)
111157 . = ALIGN (4 );
112158 } > ITCM AT> FLASH_FIRMWARE
113159 _ld_itcm_destination = ADDR (.itcm );
@@ -119,6 +165,9 @@ SECTIONS
119165 . = ALIGN (4 );
120166
121167 *(.dtcm_data .*)
168+ *dcd_ci_hs.o (.rodata *)
169+ *py/objboundmeth.o (.rodata *)
170+ *py/objtype.o (.rodata *)
122171
123172 . = ALIGN (4 );
124173 } > DTCM AT> FLASH_FIRMWARE
@@ -139,7 +188,7 @@ SECTIONS
139188 _ld_dtcm_bss_start = ADDR (.dtcm_bss );
140189 _ld_dtcm_bss_size = SIZEOF (.dtcm_bss );
141190
142- .stack :
191+ .stack (NOLOAD) :
143192 {
144193 . = ALIGN (8 );
145194 _ld_stack_bottom = .;
0 commit comments