0

Everything you wanted to know about bootloading but were afraid to ask.
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Everything you wanted to know about bootloading but were afraid to ask.

by osbock on Mon Jan 30, 2012 11:21 pm

On my way to making an SD card boot drive for arduino, I documented the bootloading mechanism and protocol. I welcome corrections and questions.

http://baldwisdom.com/bootloading/

Thanks,
Kevin

osbock
 
Posts: 146
Joined: Tue Jan 23, 2007 1:12 pm

Re: Everything you wanted to know about bootloading but were afraid to ask.

by westfw on Tue Jan 31, 2012 5:49 am

A little secret is that you can actually burn this bootloader into your older arduinos (at least at atmega168 and greater) and then just refer to the board as an UNO.

Optiboot also supports the mega8. However, you can only call a board an Uno if it at has a m328 cpu in it. For m8 and m168s with optiboot, you'll need to make a new entry in boards.txt that copies the Uno bootloader parameters, but has the correct "build.mcu" specification (and fuses, if you want to program the bootloader using the IDE.)
except the signature reading is slightly different.

how so? Note that the bootloader does not actually read the chip signature, it just returns whatever value was compiled in. This lets you be sneaky and program a m328 with a m328p bootloader (they have different signatures but work the same, mostly.) The Arduino IDE will never know the difference.
Then it reads several pages (probably to verify what it wrote)

Yep. You should move the part about "leave programmer mode" AFTER the log of reading the pages. It's a bit confusing as-is...

Arduino MEGA (1280 and 2560) use yet another bootloader, one that uses the stk500v2 protocol instead.

Otherwise, nice job.

I want to point out that STK500v1 is a pretty awful protocol for a bootloader. This is the protocol originally implemented for Atmel's STK500 device programmer/eval board, and has a lot of commands related to controlling the behavior of hardware that a bootloader would never be able to do. Optiboot saves a lot of space by responding to any command that it doesn't recognize with either "OK" or "3", which leaves me feeling pretty uncomfortable about it.
westfw
 
Posts: 1568
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Everything you wanted to know about bootloading but were afraid to ask.

by osbock on Tue Jan 31, 2012 7:48 am

Awesome Info! Thanks for spotting the editing mistake, I've updated the section about optiboot (how would you like to be credited? I saw your handle in the code, but didn't know how to trace it back to you. Right now it links back to your post here.)

The part about reading the signature came from the avrdude code. It looks like there isn't a vanilla stk500 signature routine. There's one for avr910, stk500v2 and one specifically arduino.
I think I'll edit that comment out. (however, the bit about using 328's is useful, I have a handful of them ordered by mistake, and I have replaced processors in arduinos with them. It does take a boards.txt entry to burn them from arduino, though it's trivial to burn them from the command line.)

osbock
 
Posts: 146
Joined: Tue Jan 23, 2007 1:12 pm

Re: Everything you wanted to know about bootloading but were afraid to ask.

by westfw on Tue Jan 31, 2012 1:40 pm

(how would you like to be credited? I saw your handle in the code, but didn't know how to trace it back to you. Right now it links back to your post here.)

Add a pointer to the google code optiboot project? http://code.google.com/p/optiboot/
That's also the preferred place to submit bug reports, check for newer code, etc. (atmega1284 now supported!)
westfw
 
Posts: 1568
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Everything you wanted to know about bootloading but were afraid to ask.

by osbock on Tue Jan 31, 2012 2:28 pm

Done! Thanks!

osbock
 
Posts: 146
Joined: Tue Jan 23, 2007 1:12 pm

Please be positive and constructive with your questions and comments.