Place specific functions on RAM memory using custom linker script

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Place specific functions on RAM memory using custom linker script

2,499 次查看
jose_au_zone
Contributor II

Hello!

I'm trying to write a bootloader for the 1062 with a custom board running XIP from a external hyperflash

This bootloader needs to be able to erase/read/write from the same hyperflash it is XIPing from.

I've got to a point where I think I need to place the functions that actually erase/read/write the hyperflash in RAM, since looks like it's not possible to do such operations while also running code from the hyperflash
(I say that due to this topic: https://community.nxp.com/t5/i-MX-RT/i-MX-RT1050-FlexSPI-XIP-and-Write-to-Flash/m-p/718937?ru=314130...

I was going through the MCUXpresso User Guide and looks like using the "linkscripts" (or using the __RAMFUNC macros) would be the way to do that. But looks like one can only use such methods when using the automatic linker manager (Manage linker script checkbox checked in MCU Linker->Managed Linker Script)
So what I want to know is how can I achieve this while using a custom linker script.
Is there a specific syntax that I need to follow in my custom linker script?

Thank you so much!

标签 (1)
0 项奖励
回复
5 回复数

2,487 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jose_au_zone ,

  If you want to use the secondary bootloader in the RT1060, you totally can refer to our SDK ota_bootloader, that can operate the external flash directly, it is the QSPI flash in default, you just need to modify it to the hyperflash is OK.

  Please refer to my doc:

https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/RT1060-OTA-bootloader-ISP-and-swap-rollback-usag...

  The SDK path is:

SDK_2_10_0_EVK-MIMXRT1060\boards\evkmimxrt1060\bootloader_examples\ota_bootloader

 Please check it at first, thanks.

Best Regards, 

Kerry

0 项奖励
回复

2,479 次查看
jose_au_zone
Contributor II

Hi Kerry

I think you missed the main point of my question: 

I've already tried to use the .ldt files on the linkscripts folder, and it didn't work

I've also already tried to _RAMFUNC macros and it also didn't work

It looks like everything I did was completely ignored by the compilation process, and the program counter is still using hyperflash addresses when it jumps into the some of the functions I tried to put into RAM.

One thing that I realized is that in the example projects that I've tested which put some function calls on the RAM they always have the "Manage linker script" option checked. Which means that they are NOT using custom linker script

I'm my case, I am using a custom linker script, therefore the "Manage linker script" option is UNCHECKED in my bootloader project

And this is what I want to know: how can I make this work while also working with a custom linker script

I am attaching my bootloader project as is right now.

You will notice that I've added the linkscripts folder, added two files inside of it: data.ldt and main_text.ldt

I was trying to follow the example from the project: evkmimxrt1060_lwip_httpssrv_ota_freertos to try and put some functions into RAM.


I also added the __RAMFUNC(SRAM_ITC) keyword before the flexspi_nor_wait_busy function to try to reallocate it to the ITC memory.

Both methods didn't work and I guess this is happening because I'm using a custom linker script (middleware/mcu-boot/MIMXRT1062_flash_bootloader.ld)

Is there any specific syntax I need to follow? Could you provide a snippet of code that I could use, either in the linker script directly or in the C source code, that places a specific function into RAM memory?

Thanks!

0 项奖励
回复

2,467 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jose_au_zone 

  To the function defined in the RAM, after the memory is defined,  __RAMFUNC(SRAM_ITC) should work directly, but to flexspi operation run in RAM, normally, we put the whole project :

SDK_2_10_0_EVK-MIMXRT1060\boards\evkmimxrt1060\driver_examples\flexspi\hyper_flash\polling_transfer

link to RAM and run it.

  In fact, to your situation, you totally can use the ROM API instead of copy the flexSPI driver to the RAM, in fact, the ota_bootloader also use the ROM API. If you use the ROM API, you totally can run it in the flash directly, the sample code you can refer to OTA_bootloader or ROM API project:

SDK_2_10_0_EVK-MIMXRT1060\boards\evkmimxrt1060\driver_examples\fsl_romapi

  About the function copy to RAM, when I define the code, I even didn't modify the ld file, I just define it like this:

_RAMFUNC(RAM4) void SysTick_DelayTicks(uint32_t n)
{
g_systickCounter = n;
while (g_systickCounter != 0U)
{
}
}

 

Then the map file you can find the SysTick_DelayTicks in RAM4.

kerryzhou_0-1627360166539.png

Your project is based on the flashloader or the ota_bootloader? If you are based on the ota_bootloader, you don't need to copy the flexspi driver to the RAM, just use the ROM API.

If your customer API want to copy to RAM, you can define a new ram range, then define your API to RAM with _RAMFUNC(NewRAM).

Best Regards,

Kerry 

 

 

0 项奖励
回复

2,448 次查看
jose_au_zone
Contributor II

Hi Kerry

I was using the ROM API, but it was not working ,and another employee suggested me to use the flex API directly, that's why I'm not using the ROM API

The topic is this one:

https://community.nxp.com/t5/i-MX-RT/External-FlexSPI-initialization-in-bootloader-for-1062/m-p/1312...


I can try to put the whole project, but like I said the macros __RAMFUNC are not working, they are being ignored, and I suspect this is because I'm using a custom linker script. Could you confirm that this should work even when the option "Manage Linker script" is not selected (i.e. a custom linker script is bein used)?

 

0 项奖励
回复

2,443 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jose_au_zone 

  I have checked your project yesterday, if just define it to the ITCM, and the map still in the external memory.

  Just confirm your function again, do you want to use the secondary bootloader which can operate the hyperflash when the bootloader code already running in the flash, right? If yes, as the RT1060 contains the ota_bootloader, that just meet your demand, but that project is using the QSPI, what you need to do is to modify option, then the ROM API will help you do it. do you mind to use this way instead of porting your project?

   SDK_2_10_0_EVK-MIMXRT1060\boards\evkmimxrt1060\bootloader_examples\ota_bootloader

 I think to try this method will save your time.

eg: bootloader_config.h

Modify from:

// The FLASH is a QSPI FLASH which supports JESD216 standard, working at 120MHz
#define BL_FLEXSPI_NOR_CFG_OPT0 (0xc0000006u)
#define BL_FLEXSPI_NOR_CFG_OPT1 (0x0u)

To hyperflash:

// The FLASH is a hyer 3V0, 100Mhz

#define BL_FLEXSPI_NOR_CFG_OPT0 (0xc0333006u)
#define BL_FLEXSPI_NOR_CFG_OPT1 (0x0u)

kerryzhou_0-1627440526294.png

Then you can try to test it directly.

If you meet any issues, just kindly let me know.

 

To your linker issues, I think you need to make sure: 1. RAM is enough to use, 2. divide one RAM range mainly used for your own API function.

In your shared another link, seems your previous RT1064 ROM API method totally works, just the RT1060 can't work, right? If yes, please modify the option which I suggest you, just use the hyperflash option as I know, the RT1060 totally can support the get_config() function.

If you still have issues, just kindly let me know, when I have time, I will also try to modify the SDK rt1060 ota_bootloader to hyperflash.

If your RT1064 already works with the ROM API, just keep patient, your RT1060 will also can be successful.

Best Regards,

Kerry

 

 

 

 

0 项奖励
回复