I have a problem with the CW linker placement of a library.
I'm not quiet sure which whether this is a Classic CodeWarrior question or a Coldfire question. I'll start here because although I'm writing for a MCF51 I'm also working in Codewarrior 6.3.
I have managed to implement the famed AN2295 bootloader for my current project. As any of you who have gone there know, the micro side of AN2295 is written in assembly language. My requirements, however, require significant additional bootloader complexity. As my Coldfire assembler skills are minimal, I have embarked on a C language bootloader.
I have the code roughed out and embarked on testing. Examining my project MAP file, however, has demonstrated a disquieting characteristic..
First, my project.LCF file (which is shared with the application) defines memory thusly:
MEMORY {
vectors (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000410
BootLoad (RX) : ORIGIN = 0x00000410, LENGTH = 0x00000BF0
VectorReMap (RX) : ORIGIN = 0x00001000, LENGTH = 0x00000400
code (RX) : ORIGIN = 0x00001400, LENGTH = 0x0003EBFF
NVRAM (RW) : ORIGIN = 0x00800000, LENGTH = 0x00000020
userram (RW) : ORIGIN = 0x00800020, LENGTH = 0x00007FE0
standbyram (RWX) : ORIGIN = 0x00FF8680, LENGTH = 0x00000020 #SM
}
Checking the bootloader project.abs.xMAP file finds the following:
# .text_bootload
00000410 00000004 .text_bootload __initialize_system (startcf.c)
00000414 0000001C .text_bootload __copy_rom_section (startcf.c)
00000430 00000038 .text_bootload __copy_rom_sections_to_ram (startcf.c)
00000468 00000004 .text_bootload _ExitProcess (startcf.c)
0000046C 00000074 .text_bootload clear_mem (startcf.c)
000004E0 00000090 .text_bootload _startup (startcf.c)
00000570 0000003C .text_bootload main (main.c)
...etc...
# .text
00001400 0000001C .text __call_static_initializers (librt.a cf_staticinitia)
0000141C 0000002C .text __destroy_global_chain (librt.a cf_staticinitia)
00001448 0000003C .text __lmodu__ (librt.a cf_runtime.o )
00001484 0000000C .text _ewl_exit (librt.a abort_exit.o )
Observe while all my bootloader code is in the segment .text_bootload (as it should be), the linker as also included four library functions and placed them not in the .text_bootloader space but in the .text segment. The .text area is, of course, intended for the application and will be erased and overwritten by the bootloader code. Obviously, having bootloader lib functions in the application space is un-good.
Has anyone any idea how to direct CW 6.3 to either:
I find __call_static_initializers() is called from startcf.c so that I can modify that to exclude the function (and be careful NOT to statically initialize anything), but the others libraries are not explicitly referenced so I'm at a loss how to be rid of them.
Thanks for any thoughts,
Doug
Hello Doug,
I'd recommend you to add the list these functions explicitly into the bootloader section:
e.g.:
.text_bootload :
{
OBJECT (___call_static_initializers , librt.a)
OBJECT (___destroy_global_chain , librt.a)
OBJECT (___lmodu__, librt.a)
OBJECT (__ewl_exit, librt.a)
...
}> BootLoad
Note: Add one underscore character at the beginning of each object name. Seems to be a manual issue since this is not documented....
To place entire library into a section you can use e.g.:
.text_bootload :
{
librt.a (.text)
...
}> BootLoad
Hope it helps.
Stan
Well, thinking about this a bit, an easy solution would be to give the bootloader project it's own unique .LCF file which is sort of the compliment of the application projects .LCF file. That is. the bootloader LCF would have only one flash MEMORY declaration, which would cover the same space as the text_bootloader segment of the application.
Not very elegant, and likely to bite if the bootloader size requirements expand (which is likely). I just hope I can remember then to make adjustments in two LCF files....