Help with gcc and ld relative linking

I'm trying to create and s19 from a binary (for Coldfire 5485 micro) using objcopy. I need to specify a PC relative output but I can't seem to get a valifd binary when I use the "-r" option on the linker (ld).

The code builds and runs on the micro but it's running in flash. I just want to relocate it to RAM. When I use the -r option though, I get an invalid binary and the s19 file just keeps growing until I kill objcopy.

Any thoughts, hints, suggestions would be GREATLY appreciated!!

Reply to
James Kimble
Loading thread data ...

First, you can't turn code generated with absolute addresses into position independent code - you need to specify the right switches to the compiler to generate PC-relative addressing (I can't remember offhand, but it's something like -fPIC and -fPID).

There are a couple of easier ways to handle your problem, however. One is that you can have independent load-time and run-time addresses for your code - addresses in RAM are used during linking and at run-time, but the code segment is packed into a flash address. You need a startup section that is linked to flash addresses and runs first, copying over the code into RAM.

Another method is to always build your binary with RAM addresses at 0. Your startup code first maps the RAM to a higher address, then copies over the entire program section to RAM. Then do a relative jump to move the PC to the next logical instruction, but running from the RAM copy. Remap the flash to a different address, jump to that copy, then remap RAM to 0 and jump to that copy.

You can also use a more sophisticated bootloader, depending on the application and what else you have in the system.

Reply to
David Brown

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.