Run code from SRAM after copying data from Flash to SRAM MPC5748G

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Run code from SRAM after copying data from Flash to SRAM MPC5748G

210 Views
shkh
Contributor I

Hello,

I am using MPC5748G

I am working on bootloader which can download new bootloader.

for this purpose i need to copy the code from flash to SRAM so that i can erase the flash and write new data into flash.

I wrote a function which is copying data from flash to sram and putting into the partition of the sram.

and after copying i am jumping to the function which is in SRAM and but i have observed SW is not running form SRAM its still running from flash this i can verified with debugger by seeing the disassembly code and PC.

Please help me out.

0 Kudos
Reply
6 Replies

179 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

you can refer to below thread for a guide how to execute a selected function out of RAM memory 
https://community.nxp.com/t5/S32-Design-Studio-Knowledge-Base/HOWTO-Run-a-routine-from-RAM-in-S32-De...
Hope it helps.

BR, Petr

0 Kudos
Reply

82 Views
shkh
Contributor I
Hello,

could you please reply
0 Kudos
Reply

177 Views
shkh
Contributor I

Hello,

Thanks for reply

I dont want to run some functions from SRAM. My target is copy whole data from Flash to SRAM using __TEXT_END symbol that can give me the size of the Flash data and copied to SRAM specific section (user defined) and then jump to the function which is copied into SRAM from FLASH.

example:

typedef void (*tRamLoop)(void);

extern const uint32_t __TEXT_END;
extern const uint32_t __SSRAM_LOOP_START_ADDR; /* from linker script */
extern const uint32_t __SSRAM_LOOP_SIZE; /* from linker script */
extern const uint32_t __start;

/**
* Main bl handler function (running in ram)
* \return void
*/
static void ramLoop()
{

/* Start the scheduler */
vTaskStartScheduler();
}

/**
* Function runs in flash and copies codebase from flash
* to ram in order to execute the main bl function in ram.
* \return void
*/
static void copyToRam()
{
unsigned long cntl = (unsigned long)&__TEXT_END;
unsigned long cnts = (unsigned long)&__start;
unsigned long *psrc=(unsigned long *)&__start;
unsigned long *pDst = (unsigned long *)0;

unsigned long dst = (unsigned long)&__SSRAM_LOOP_START_ADDR;
unsigned long size = (unsigned long)&__SSRAM_LOOP_SIZE;

/* size of the text in flash */
unsigned long textSize = cntl - cnts;


tRamLoop pRamLoop = NULL;

/* Make sure RAM offset is a multiple of 8 */
while (dst % 8 != 0)
{
dst++;
}

/* Calculate where to jump */
pRamLoop = (tRamLoop)(ramLoop + dst - cnts);

/* Copy to ram */
pDst = (unsigned long *)dst;
textSize /= 4;
while (textSize--)
{
*pDst++ = *pSrc++;
}

/* Jump */
pRamLoop();

}

 

copyToRam function is called in the main after board initialization.

0 Kudos
Reply

73 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

is really pRamLoop properly set and points to RAM area where function is copied?
I can recommend to step through assembler and check register contents.

BR, Petr

0 Kudos
Reply

64 Views
shkh
Contributor I
yes pRamLoop is points to SRAM address but after this call i can not debug step by step it just run and scheduler is start and then i can see its running from FLASH(can see disassemble code address is from FLASH)
0 Kudos
Reply

40 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

this code is not position independent. Only code that has been compiled for RAM can be copied to RAM. See How to guide, I mentioned above, how to do that.

BR, Petr

0 Kudos
Reply