Tuesday, October 5, 2010
What's A Bootloader?So we've got our platform in a state where we can load new firmware onto it with our programmer. That's great but what if we need to update the platform after we've built some units and sent them off to end users? I guess we could give them all a Pickit and instructions on how to use it. FAIL. We need a better way than that. We need a bootloader. What's a bootloader? Simple, a bootloader allows our microcontroller to be reprogrammed WITHOUT our Pickit.
Basic OperationWhen we use the Pickit, or any other programmer for that matter, ones and zeroes are sent on the programming pins after the microcontroller is put into a special programming mode. The microcontroller writes that data into program memory. Most of the PIC microcontrollers nowadays have a “self-write” capability which means that they are capable of writing to their own program memory space during normal operation without going into a special programming mode. We have to be careful though because if we put new programming instructions in the wrong addresses the microcontroller will exhibit unpredictable behavior or stop working altogether until we reprogram it with our Pickit.
When the unit is powered up we can have a small piece of code that checks some type of flag(button pressed, entry in EEPROM memory) to determine whether to run the application code or run the bootloader code. The bootloader code has some mechanism for getting the new firmware instructions into the application code program memory, overwriting the old application code in the process.
Bootloader SpecI've thought a lot about the best way to implement a bootloader for the EmbeddedFun Sensor Platform. Taking into consideration ease of use and functionality I think the best option is to use an SD card. We can put new firmware on the SD card and the next time they reset the device it can check for new firmware and load it into program memory as well. How we get the firmware onto the SD card is also up to us.
The platform could implement the Mass Storage USB class so we could copy firmware to it like any other external drive or maybe we could get it there wirelessly. The SD card provides other benefits as well. It gives us a ton of storage that the platform can use for things like storing sensor data, settings and other things. Episodes 3 and 4 will cover implementing the bootloader for our sensor platform. Topics covered will include:
- Reading/Writing to flash program memory on the PIC
- Communicating with an SD/uSD card
Posted by K-Sid at 8:35 PM