Speed up you uploads with the write boot option in Averdude


2 Second Arduino Bootloader
written by Noah Bedford  [permalink]

The Arduino "write bootloader" option is slow. Why?
When writing the fuses to the AVR for the first time, the bitclock needs to be at ~200KHz. 
After that, you can crank the speed all the way up to 4MHz.
The option for this is -B, and it's not particularly well documented; lfmorrison on the AVRdude forums says:
"note that the feature of setting SCK duration is only available in avrdude if you're using an AVRISP with 2.xx firmware. In that case, the SCK duration, in microseconds, is specified after the parameter -B. (eg. -B 1000 would be a request for a bit clock of 1000 microseconds, or 1 millisecond, or a SCK frequency of 1 kHz. The parameter closest to the desired frequency, without exceeding it, will be chosen.)

If you're using version 1.xx firmware, avrdude doesn't know about setting the bitrate. You'd have to either:
1) Use different programming software that does support setting the ISP SCK Duration parameter in version 1.xx of the firmware, or
2) Upgrade the AVRISP firmware to version 2.xx inside AVR Studio first, or
3) Modify the avrdude source code to attempt to adjust the STK500 ISP SCK Duration parameter using the -B command-line option, using the implementation from STK500v2 as a guide. (keeping in mind that the translation from SCK parameter to physical SCK frequency is probably different in the two firmware versions...)"
So we run:
avrdude -c avrispmkii -p m328p -B 5 -u -U lock:w:0x3f:m -U efuse:w:0x05:m -U hfuse:w:0xDA:m -U lfuse:w:0xFF:m -P usb
avrdude -P usb -c avrispmkii -p m328p -u -U flash:w:ATmegaBOOT_168_atmega328.hex -U lock:w:0x0f:m -B .2