This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Copy C-Lib to RAM using the linker

Hi all,

I've got a question regarding a bootloader written for the XE167.

Part of the bootloader needs to be executed in RAM in order to erase and reprogram the FLASH. I placed the flash-routines in their own section and advised the linker to execute them from the RAM.

When looking at the ASM-output of the routines I noticed that there are some calls to the C_SCALLI-function of the C-Lib within these routines.
Because of these calls I need to copy the C-Lib code to the RAM, too.

The thing is that I need to copy the code from FLASH to RAM before erasing the FLASH. With the flash-routines it was quite easy using the SROM_PS-macros (according to appnotes 141 and 138). This works fine.
Copying the C-Lib using hard coded addresses works fine as well, but for obvious reasons I'd like to use macros to determine the start and end address of the C-Lib as well.

So here's what I tried (according to http://www.keil.com/support/docs/2374.htm):

#define SROM_MC(n)                                                  \ 
extern unsigned char huge _##n##_s_;  /* section source start */ \ 
extern unsigned char huge _##n##_l_;  /* section len          */ \ 
extern unsigned char huge _##n##_t_;  /* target address       */

#define SROM_MC_TRG(n) ((void *)       &_##n##_t_)
#define SROM_MC_SRC(n) ((void *)       &_##n##_s_)
#define SROM_MC_LEN(n) ((unsigned int) &_##n##_l_)

SROM_MC (C_LIB_CODE)
hmemcpy (SROM_MC_TRG(C_LIB_CODE), SROM_MC_SRC(C_LIB_CODE), SROM_MC_LEN(C_LIB_CODE));

Now I can use these macros within my code without getting compiler errors, but the linker cannot find the symbols "_C_LIB_CODE_l_", "_C_LIB_CODE_s_" and "_C_LIB_CODE_t_" (unresolved externals). So this tells me that the symbols for the SROM-section of the C-Lib are not created.

How can I create these symbols?

Thanks in advance for any help.

With best regards

P.S.: If it's of any help, here's part of the generated M66-file:

C04000H   C04827H   000828H   CODE  REL   WORD   ---  ---  PUBL  SROM    ?PR?SR1_FLASH
*** '?C_LIB_CODE'  execution at: E09000H
C05000H   C0502BH   00002CH   CODE  REL   WORD   ---  ---  PUBL  SROM    ?C_LIB_CODE
*** '?PR?SR1_FLASH' stored at: C04000H   execution at:
E08000H   E08827H   000828H   CODE  REL   WORD   ---  ---  PUBL  XCODE   ?PR?SR1_FLASH
*** '?C_LIB_CODE' stored at: C05000H   execution at:
E09000H   E0902BH   00002CH   CODE  REL   WORD   ---  ---  PUBL  FCODE   ?C_LIB_CODE

0