I'm trying to port some code to SDCC (HC08).
This code includes a routine that erases/write a flash sector.
this routine needs to run from RAM. so I have another routine that copies the code to RAM during initialization…
My question is how do I achieve this with sdcc. I figured out that I can relocate the erase/write routine using the -Wl -b option.
But then I need the linker to actually insert the code in flash (although it's linked for execution in RAM) and pass the starting address and length of that segment into my "copytoram" routine so that it can move the code at initialization.
How is this done? Has anybody had to deal with something like that?
I would link the code for execution in RAM. Then I would post-process the hex-file to move this area into flash so that at runtime it can be copied from flash to ram. For post-processing srecord can be used. http://srecord.sourceforge.net
Thanks for your reply maartenbrock.
Post processing with srecord will work, but seems like a really involved process:
I would have to first compile and link the whole program to determine it's length, then manually insert the start address and length of the code that needs to be moved to RAM, recompile and relink the whole thing, and finally post process with srecord.
I was hoping for a simpler solution… :-)
Can the linker insert the start address and length of the relocated segment automatically? ( other linkers have variables like _START_FLASHSEG, _END_FLASHSEG that can be used for that.)
Thanks again for your help
Which HC08 do you use? Some of them got flash handling routines in ROM - they can be safely called there, altough some versions are buggy - JB8 for example.
I'm using MC9s08qg, so there are no ROM routines on that one…
I would put the code in a named segment (-codeseg) and locate this segment in RAM (-Wl-b=0x8000).
Then I'd reserve a piece of flash for the image, e.g. 0x7000-0x7FFF and use srecord to move the hex-file contents.
At runtime I'd copy the whole image.
In assembler (not in C) there indeed are symbols representing the start and length of every segment. See the mape-file. With some assembler help you could get them into C variables/constants.
Log in to post a comment.