AnsweredAssumed Answered

C Bootloader: Controlling library location

Question asked by Doug Paulsen on Jul 18, 2014
Latest reply on Jul 25, 2014 by stanish

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:



   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)



  # .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:


  1. Include librt.a in the .text_bootload space, or
  2. Preferably exclude librt.a altogether?


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,