I have a board that features a Freescale Kinetis K60 MCU and I want to write a bootloader for it but I don't have hardware in place to signal it after a reset to go into "load new firmware" mode vs. "normal operation" mode. What are my alternative possibilities? Can I set a flag in flash to signal the bootloader to enter one or the other mode? How would I do this? Any ideas?
That really depends on how complex a bootloader you want to write, and what you have in place in the way of communications options.
For example, if the bootloader is using a UART to take in the application code, you could include a minimal console (menu-driven, for simplicity) in the bootloader that allows you to issue various commands, e.g. erase the existing application, start the existing application, or load a new application. Include a startup timeout - if you don't press a key within 3 seconds of boot, it automatically starts the existing application, if there is one, otherwise it stays in the menu waiting for an application to be loaded.
If the bootloader implements a simple, well-documented and widely supported serial file transfer protocol e.g. Y-Modem (yes, Z-modem is far, far better, but it's complicated), then you can upload application binaries from just about any terminal program.
That's actually pretty simple. The steps are as follows:
- Define a section for the linker where your special flash page will be stored
- Make sure that both bootloader and application know about this section
A good example is outlined here: http://mspgcc.sourceforge.net/faq/x71.html, although it's not special for the K60 family.
You will also need to figure out where you are going to place that section. I would reserve one full page near the end of the flash. If this is where your stack is stored, you might want to go forward before that section. Your linker file should tell you about your sections.