You may be able to use the same approach TinyOS does, using some linker flags. An example for an msp430f1611:
CFLAGS += -Wl,--section-start=.text=0x4a00,--defsym=_reset_vector__=0x4000 So when compiling/linking the application, it moves the text segment up and defines the _reset_vector__ to point at the bootloader. You don't even need a separate linker script. However, redefining __reset_vector_ apparently makes the compiler discard some symbols referenced from it, which are then manually added back in. The full sequence is: CFLAGS += -Wl,--section-start=.text=0x4a00,--defsym=_reset_vector__=0x4000 # Pull back in mspgcc CRT code discarded by the redefinition of _reset_vector__ CFLAGS += -Wl,--undefined=__init_stack CFLAGS += -Wl,--undefined=__low_level_init CFLAGS += -Wl,--undefined=__do_copy_data CFLAGS += -Wl,--undefined=__do_clear_bss CFLAGS += -Wl,--undefined=__stop_progExec__ CFLAGS += -Wl,--undefined=_endless_loop__ HTH, Michiel > -----Original Message----- > From: Tomek Lorek [mailto:tlo...@gmail.com] > Sent: Friday, April 18, 2014 19:09 > To: mspgcc-users@lists.sourceforge.net > Subject: [Mspgcc-users] Can the RESET_VECTOR be redefined at compile > time to a specific value? > > Hi, > My use case is the following: I have a bootloader (up to 4K in size, > residing at 0x4400 to 0x5400) that has a main() function and > application (starting from 0x4800) – they are organized as 2 separate > projects (I want the bootloader to be flashed only once and not > changed later). > > I am using mspgcc. > > Bootloader and application linker scripts are defined so that their > .text sections (that go to “rom” memory region) are separated but they > use the same “vector” memory region for .vector section (although the > bootloader does not use any interrupts other than reset): > > bootloader’s linker script excerpt: > MEMORY { > … > rom (rx) : ORIGIN = 0x4400, LENGTH = 0x1000 /* END=0x5400, > size 4K - bootloader code */ > rom_app (rx) : ORIGIN = 0x5400, LENGTH = 0xab80 /* END=0xff80, > size 43904 - the field-updatable application */ > vectors : ORIGIN = 0xff80, LENGTH = 0x0080 /* END=0x10000, > size 128 as 64 2-byte segments */ > … > } > > and the application’s linker script excerpt: > > MEMORY { > … > rom (rx) : ORIGIN = 0x5400, LENGTH = 0xab80 /* END=0xff80, > size 43904 */ > vectors : ORIGIN = 0xff80, LENGTH = 0x0080 /* END=0x10000, > size 128 as 64 2-byte segments */ > … > } > > I need the bootloader’s init code and main() function be executed upon > power up of the microcontroller. And this would be the case if I only > flash the bootloader’s .elf onto the flash (0xFFFE pointing to > bootloader’s main() function). > > But when I then program the application’s image onto the flash the > 0xFFFE will point to the application’s reset vector which is not a > bootloader anymore. I'd like to configure my application so that it > always fills 0xFFFE with a fixed address (0x4400). > > The rest of the story is that when bootloader is started then of > course the bootloader needs to jump to and execute the application’s > entry point (0x5400) including the app's watchdog preparation, stack > init etc. > > Is that doable? How can I define in the application’s code that the > reset vector (0xFFFE) shall contain the bootloader’s init code > (0x4400)? > > Best Regards, > Tomek > > ----------------------------------------------------------------------- > ------- > Learn Graph Databases - Download FREE O'Reilly Book > "Graph Databases" is the definitive new guide to graph databases and > their > applications. Written by three acclaimed leaders in the field, > this first edition is now available. Download your free book today! > http://p.sf.net/sfu/NeoTech > _______________________________________________ > Mspgcc-users mailing list > Mspgcc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mspgcc-users ------------------------------------------------------------------------------ Start Your Social Network Today - Download eXo Platform Build your Enterprise Intranet with eXo Platform Software Java Based Open Source Intranet - Social, Extensible, Cloud Ready Get Started Now And Turn Your Intranet Into A Collaboration Platform http://p.sf.net/sfu/ExoPlatform _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users