cancel
Showing results for 
Search instead for 
Did you mean: 

Linking 2 different hex files

rajivpatil61
Associate II
Posted on December 15, 2014 at 02:55

Hi,

How can i link 2 different hex files at 2 distinct memory locations?

for example at 0000h i have my main code and at 4000h i have my application code. app code must access the functions in main code, so since i upload 2 different hex files, how can i link them

Thanks,

Rajiv

#stm32f4 #discovery #rtfm
4 REPLIES 4
Posted on December 15, 2014 at 06:38

Initially I thought you wanted to merge two hex files.

To link functions you're best route would probably be to provide a jump table, or array of function pointers, and access the functions that way. That would be robust to version changes, and routines moving. In a more classical sense you could take function addresses exported by a loader, and then feed them as definitions (.DEF file, or hard links) to the linker for the application.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rajivpatil61
Associate II
Posted on December 16, 2014 at 06:18

Ok, but If i add the jump table in the main, then how can i link it to the app??

Posted on December 16, 2014 at 17:37

Ok, but If i add the jump table in the main, then how can i link it to the app??

Well this would depend a lot on the tools you're using, the portability expectations, and the necessity to have two separately compiled pieces of code calling backward and forward into each other.

If the loader is in Masked ROM, the case is a lot easier because things won't move. On an Cortex-Mx I'd be temped to build a function table that extends beyond the regular vector table, uses SVC, or a single entry point function with a switch/case.

http://www.rmbconsulting.us/jump-tables-via-function-pointer-arrays-in-cc

For GNU/LD there's -defsym, and defining a symbol directly in the sections portion of linker script. You might have to write a small script to extract addresses from the .MAP file of one component, and add them into the .LD of the other component(s), if you want to automate the linkage.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rajivpatil61
Associate II
Posted on December 17, 2014 at 09:55

Thank you, this helps me a lot :)