In MCUXpresso I cannot set up the BCA anymore

cancel
Showing results for 
Search instead for 
Did you mean: 

In MCUXpresso I cannot set up the BCA anymore

5,548 Views
laszlomonda
Contributor IV

Hi there,

I've migrated my project from KDS to MCUXpersso, and I cannot setup the BCA anymore.

Previously, I've added the following code to the linker file:

MEMORY
{
m_bootloader_config(RX) : ORIGIN = 0x000003C0, LENGTH = 0x00000040
}

SECTIONS
{
.bootloader_config :
{
. = ALIGN(4);
KEEP(*(.BootloaderConfig)) /* Bootloader Configuration Area (BCA) */
. = ALIGN(4);
} > m_bootloader_config
}

Now, MCUXpresso has the "Manage linker script" feature that generates a different linker script. I disabled this feature, so that the already generated script doesn't get overwritten, and added the the above to the end of the generated linker script. This resulted in the following error message:

/usr/local/mcuxpressoide-10.0.0_344/ide/tools/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: section .bootloader_config loaded at [000003c0,000003df] overlaps section .text loaded at [00000000,00001797]

I understand the nature of the issue that the memory sections overlap but I don't have deep knowledge regarding the memory sections of the MCU or linker scripts, so I could really use some help.

Ideally, I'd like to use a solution that keeps using the "manage linker script" feature and adds a new file for this purpose, but it's not a requirement.

You can see my linker script, and my whole MCUXpresso project.

Thanks in advance!

- Laci

14 Replies

3,804 Views
Lorac
Contributor III

Hi all, it's not so easy to do it, but i did.

I'm referring to MCUXpresso User Guide Chapter 17.3.

You must modify some linker script template to add BCA section in the PROGRAM_FLASH memory region.

  

See the file:

..\Wizards\linker\main_text_section.ldt

Modify all lines that you need. It'is the <linker.ld> template used by FreeMarker engine that create your linker script file.

And so one...

Regards

CD

3,804 Views
lewismarkwell
Contributor II

Hi Carol,

Glad to hear you had some success!

Would you be willing to share the linker script you made to add BCA section into PROGRAM_FLASH? I am still not having much success.

Much appreciated if you can.

3,804 Views
deniscollis
Contributor V

Important:  Do not create a separate section for the BCA.  What we're trying to do here is keep the BCA at a specific address in the PROGRAM_FLASH section.

I'm using the 'old school' way -- i.e. manually editing the .ld scripts.  Here's an excerpt that shows the equivalent of what Lorac‌ wizard mod would also produce:

:
:
SECTIONS
{
    /* MAIN TEXT SECTION */
    .text : ALIGN(4)
    {
        FILL(0xff)
        __vectors_start__ = ABSOLUTE(.) ;
        KEEP(*(.isr_vector))
        /* Global Section Table */
        . = ALIGN(4) ;
        __section_table_start = .;
        __data_section_table = .;
        LONG(LOADADDR(.data));
        LONG(    ADDR(.data));
        LONG(  SIZEOF(.data));
        LONG(LOADADDR(.data_RAM2));
        LONG(    ADDR(.data_RAM2));
        LONG(  SIZEOF(.data_RAM2));
        __data_section_table_end = .;
        __bss_section_table = .;
        LONG(    ADDR(.bss));
        LONG(  SIZEOF(.bss));
        LONG(    ADDR(.bss_RAM2));
        LONG(  SIZEOF(.bss_RAM2));
        __bss_section_table_end = .;
        __section_table_end = . ;
        /* End of Global Section Table */

        *(.after_vectors*)

        /* Kinetis BCA */
        . = 0x3C0 ;
        PROVIDE(__BCA_START__ = .) ;
        KEEP(*(.BootConfigArea))
        PROVIDE(__BCA_END__ = .) ;
        ASSERT(!(__BCA_START__ == __BCA_END__), "Linker Exfo kinetis bootloader BCA Support Enabled, but no .BootConfigArea section provided within application");
        /* End of kinetis bootloader BCA in Flash MCU */
     
        /* Kinetis Flash Configuration data */
        . = 0x400 ;
        PROVIDE(__FLASH_CONFIG_START__ = .) ;
        KEEP(*(.FlashConfig))
        PROVIDE(__FLASH_CONFIG_END__ = .) ;
        ASSERT(!(__FLASH_CONFIG_START__ == __FLASH_CONFIG_END__), "Linker Flash Config Support Enabled, but no .FlashConfig section provided within application");
        /* End of Kinetis Flash Configuration data */
    } >PROGRAM_FLASH
:
:‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Now you can populate it with:

__attribute__((used,section(".BootConfigArea"))) 
const bootloader_config_t bootloaderConfig =
{
    .tag             = 0x6766636B,
    .crcStartAddress = 0xFFFFFFFF,
    .crcByteCount    = 0xFFFFFFFF, 
    /*
    :
    ...and so on...
    :
    */
};‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

3,804 Views
Lorac
Contributor III

Here is the code that I inserted.

. = 0x3C0 ;
PROVIDE(__BCA_START__ = .) ;
KEEP(*(.BootConfigArea))
PROVIDE(__BCA_END__ = .) ;
ASSERT(!(__BCA_START__ == __BCA_END__), "Linker Exfo kinetis bootloader BCA Support Enabled, but no .BootConfigArea section provided within application");
/* End of kinetis bootloader BCA in Flash MCU */

Regards

CD

3,804 Views
lucasrangit
Contributor III

I copied this to the local override of linkscripts/flashconfig.ldt so it would end up in the PROGRAM_FLASH section and it works.

I did not override main_text_section.ldt because that would require copying all the externally included linker files into the local override directory.

3,801 Views
robertpoor
Senior Contributor I

All: I have not yet seen or figured out a complete solution to generating a BCA under mcuexpresso. This is the only reason I’m still using KDS.  

So: if anyone has the complete recipe, I’d love to see it!!!

3,801 Views
brunoalbrecht
Contributor III

I almost just found it! haha

On the "Extra linker script input section", add a new section for the interrupts:

Description: KEEP(*(.isr_vector))

Region: INTERRUPTS

Type: text

voilà!

The BCA is being correctly set on its address (0x3C0), BUT everything else is being put starting at 0x400, including the interrupt vector...

pastedImage_1.png

I was also checking the bootloader examples (somehow I managed to build a SDK that contained the bootloader) and what they do is to completely disable the Managed Linker Scripts and use an old fashioned Script, like in KDS. While we don't have a solution, this could be used.

0 Kudos

3,801 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Laci,

1. Please place the code of "

MEMORY
{
Rm_bootloader_config(X) : ORIGIN = 0x000003C0, LENGTH = 0x00000040
}

into the "xxx_memory.ld" file , for  project own MEMORY part  has includes this memory address part ,

so it overlap.

2. There also another method , using the "manage linker script" , add the memory section of "Rm_bootloader_config(X)"

in Memory details :

pastedImage_1.png

I attached a guide about how to relocate code in MCUXPresso IDE, it describe how to configure linker file.

Please check it .

Hope it helps


Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

3,801 Views
davidrea
Contributor II

Hello Alice,

I am trying to use the MCUXpresso IDE memory configuration editor to add the bootloader configuration area (BCA) section to the memory map, but getting an "Invalid memory configuration" error due to overlap:

Screenshot from 2018-04-11 07-48-30.png

Have I followed your instructions above incorrectly? There is no mention of how to manage overlapping areas in the PDF you attached about "Relocating Code and Data Using MCUXpresso".

Thank you,

David

3,801 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi David,

Of course it can't overlap.

From your screenshot , it overlap obviously.

Each section start address(Location) can't be includes in other sections.

If your Rm_bootloader_config  section want to start from 0x83c0, please reduce the Size of "PROGRAM_FLASH" to

0x3c0., then you can add another section like FASH2 after your " RM_bootloder_config" part from  0x8400 (0x83c0+0x40) .

Hope it helps

Alice

3,800 Views
davidrea
Contributor II

After a bit more wrangling with this, I think I may have it solved:

After trying various permutations of the more-complex approach above, I noticed that the system was already inserting sections for the Flash2 and Flash3 regions above the "Main Text Section" directives:

.text_Flash2 : ALIGN(4)
 {
 FILL(0xff)
 *(.text_Flash2*) /* for compatibility with previous releases */
 *(.text_Rm_bootloader_config*) /* for compatibility with previous releases */
 *(.text.$Flash2*)
 *(.text.$Rm_bootloader_config*) *(.rodata.$Flash2*)
 *(.rodata.$Rm_bootloader_config*) } > Rm_bootloader_config

.text_Flash3 : ALIGN(4)
 {
 FILL(0xff)
 *(.text_Flash3*) /* for compatibility with previous releases */
 *(.text_REMFLASH*) /* for compatibility with previous releases */
 *(.text.$Flash3*)
 *(.text.$REMFLASH*) *(.rodata.$Flash3*)
 *(.rodata.$REMFLASH*) } > REMFLASH

Rather than trying to create a new section for the application .text, .rodata and .constdata I'm trying to relocate, I overrided text.ldt with a template condition to insert them into the Flash3 section block:

<#if memory.alias == "Flash3">
 *(.text*)
 *(.rodata .rodata.* .constdata .constdata.*)
</#if>
 *(.text_${memory.alias}*) /* for compatibility with previous releases */
 *(.text_${memory.name}*) /* for compatibility with previous releases */
 *(.text.$${memory.alias}*)
 *(.text.$${memory.name}*)

This appears to successfully relocate my application (except for the vectors and startup code, which are maintained in the PROGRAM_FLASH region based on the overrides explained in section 14.11.1 of the MCUXpresso user guide) into REMFLASH:

Memory region Used Size Region Size %age Used
 PROGRAM_FLASH: 512 B 960 B 53.33%
Rm_bootloader_config: 0 GB 64 B 0.00%
 REMFLASH: 35112 B 95 KB 36.09%
 SRAM_UPPER: 1284 B 8 KB 15.67%
 SRAM_LOWER: 0 GB 8 KB 0.00%
Finished building target: My-Application.axf

I haven't been able to test this configuration on target hardware yet, but I should have that in-hand shortly to see if this approach is effective. Will report back here for anyone Googling this issue in the future.

Thanks,

Dave

3,801 Views
robertpoor
Senior Contributor I

Dave:

In a previous note, you pointed out that with:

 PROGRAM_FLASH (rx) : ORIGIN = 0x8000, LENGTH = 0x3c0 /* 960 bytes (alias Flash) */ 
 BOOTLOADER_CONFIG (rx) : ORIGIN = 0x83c0, LENGTH = 0x40 /* 64 bytes (alias Flash2) */ 
 REMFLASH (rx) : ORIGIN = 0x8400, LENGTH = 0x17c00 /* 95K bytes (alias Flash3) */ 
 ...

...that "the linker complains that there is not enough space for my 35.3KB program in PROGRAM_FLASH."  I had the same issue until I read the fine print in the Memory Editor documentation:

[Order] is important: ... code will be placed in the first RAM block, and data will be placed in the block following the one used for the code (regardless of whether the code block was RAM or Flash).

What I've done instead (admittedly a work in progress), is to order the entries so the code flash is listed first, even though the BCA appears at lower memory:

 PROGRAM_FLASH (rx) : ORIGIN = 0x4400, LENGTH = 0xb800 /* 46K bytes (alias Flash) */ 
 BOOTLOADER_CFG (rx) : ORIGIN = 0x43c0, LENGTH = 0x40 /* 64 bytes (alias Flash2) */ 
 ...

This way, you don't need to special case REMFLASH.

Now all I need to do is figure out how to generate the .bca section.  (Did you figure that out yet?)

Best,

- Robert Poor

0 Kudos

3,801 Views
brunoalbrecht
Contributor III

any news on this matter? did you manage to have a working BCA area?

I can create the correct sections (PROGRAM_FLASH area first, then an INTERRUPT area to signal the space and then the BCA area) and even give it a name (under Project Properties -> C/C++ Build -> Settings -> Managed Linker Script, on the "Extra linker script input sections", I added a "KEEP(*(.BootloaderConfig))" on the BCA region as a .rodata). The project compiles fine, but if I check the binary file created, my BCA data is being placed on the address 0x0!

Memory sections:

pastedImage_2.png

Extra linker script input section:

pastedImage_1.png

Linker file automatically created:

pastedImage_4.png

Bootloader section declaration:

pastedImage_5.png

and the binary file (note the "kcfg" in the beginning of the file)

pastedImage_6.png

0 Kudos

3,801 Views
davidrea
Contributor II

Hi Alice-

Thank you for the follow-up. I have re-mapped the flash as you advised:

PROGRAM_FLASH starts at 0x8000, size 0x3c0

Rm_bootloader_config starts at 0x83c0, size 0x40

REMFLASH starts at 0x8400, size 0x17c00

The linker script generator then produces the following regions in the _memory.ld file:

MEMORY
{
 /* Define each memory region */
 PROGRAM_FLASH (rx) : ORIGIN = 0x8000, LENGTH = 0x3c0 /* 960 bytes (alias Flash) */ 
 Rm_bootloader_config (rx) : ORIGIN = 0x83c0, LENGTH = 0x40 /* 64 bytes (alias Flash2) */ 
 REMFLASH (rx) : ORIGIN = 0x8400, LENGTH = 0x17c00 /* 95K bytes (alias Flash3) */ 
 SRAM_UPPER (rwx) : ORIGIN = 0x20000000, LENGTH = 0x2000 /* 8K bytes (alias RAM) */ 
 SRAM_LOWER (rwx) : ORIGIN = 0x1fffe000, LENGTH = 0x2000 /* 8K bytes (alias RAM2) */ 
}

As expected, the linker complains that there is not enough space for my 35.3KB program in PROGRAM_FLASH. Now I'm trying to figure out how to relocate the .text section into the REMFLASH memory region. As far as I can tell, I'm going to need to override some of the FreeMarker linker script templates. I've done so (loosely following the "Relocating majority of application into RAM" example, but instead attempting to relocate it into REMFLASH) in order to produce a final linker script output that includes:

 .text : ALIGN(4)
 {
 *startup_*.o (.text.*)
 *(.text.main)
 *(.text.__main)
 *startup_*.o (.rodata .rodata.* .constdata .constdata.*)
 . = ALIGN(4);

 } >PROGRAM_FLASH
 
 .text : ALIGN(4)
 {
 *(.text*)
 *(.rodata .rodata.* .constdata .constdata.*)
 . = ALIGN(4);
 } >REMFLASH

This breaks the build, however:

/usr/local/mcuxpressoide-10.1.1_606/ide/tools/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/bin/ld: My-Application.axf: Not enough room for program headers, try linking with -N
/usr/local/mcuxpressoide-10.1.1_606/ide/tools/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/bin/ld: final link failed: Bad value

Am I overcomplicating this? Can you provide any further guidance on relocating the remainder of the program to the new section created after Rm_flash_bootloader?

Thanks,

Dave