How to split ".text" section into two memory segments on linker .lcf file

I'm using CW 10.1 with Coldfire MCF51MM128 and I'm having problem when the code reach more than 0x0000FFE8 getting the following linker error:

>Overflow in segment: code from section: .text

>Segment reserved size is: 0x0000ffe8 -- Overflow of: 0x00000620

By default CW creates two memory segments for flash flash, as below:

code (RX) : ORIGIN = 0x00000414, LENGTH = 0x0000FFE8

code_00010410 (RX) : ORIGIN = 0x00010410, LENGTH = 0x0000FBF0

and the .text segment is declared by default as:

.text :

{

*(.text)

. = ALIGN (0x4);

*(.rodata)

. = ALIGN (0x4);

___ROM_AT = .;

___DATA_ROM = .;

} >> code

On my understanding it does this because this mcu has 2 flash controllers and @0x0000040D @0x0001040D some non volatile registers (like the flash protection registers) are located.making the memory for code non continuous.

Now, how can I tell the linker to use both memory segments ("code" and "code_00010410") for ".text" section?

The ColdFire linker is not able to split the .text section into both flash spaces automatically. It is possible however to modify the linker file and manually place code from source files to the different memory segments. There should be a document in your installation about ColdFire build tools, but just in case I attach it here. Refer to Chapter 14 about Linker usage and in particular to sections 14.5.3 and 14.6.4.

You can also find the next application note useful, which explains how to locate code to specific memory segments:

Attachments

CodeWarrior linker cannot allocate the code into two memory segments automatically. If you want to place some code into “code”, the others into “code_00010410”, you may create a new section for the source code using “#pragma define_section” in some C files, and in link command file, place this new section in “code_00010410”, and place .text in “code” by default.

For how to create a new section and allocate it in link command file, please refer to < 4 Relocating Code in ROM > in:

- Make sure that your .text2 section is defined before the .text section in the linker file, like below. This is because there is a wildcard in the .text section that will scan all of the object files, thus ignoring your references to specific files if declared later.