Use AVR-ISP-MK2 to program both bootloader (optiboot) AND program to atmel 328p?

Started by bensotek, April 01, 2015, 04:54:12 AM

Previous topic - Next topic


Hi Olimex,

the title says it all... I'm connecting an AVR-ISP-MK2 to a brand-new atmel 328p. In linux, I then do

# set fuses (12MHz crystal/clock etc)
avrdude -v -v -v -v -patmega328p -cstk500v2 -Pusb -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xde:m -Ulfuse:w:0xff:m

# install bootloader, set lock bits again
avrdude -v -v -patmega328p -cstk500v2 -Pusb -Uflash:w:/usr/share/arduino/hardware/arduino/bootloaders/optiboot/optiboot_atmega328_12.hex:i -Ulock:w:0x0F:m

# now flash my own program
avrdude -p m328p -P usb -c avrispmkii -e -U flash:w:/tmp/program.cpp.hex

Of course, the 3rd command flashes my own program, but overwrites my bootloader from step 2 in the process.

1) Is there a way to first flash the bootloader (to the bootloader section), then flash my program (to the program section), thus keeping the bootloader intact? Basically, I want to save the work of using the serial connection to the chip and actually use the bootloader during production. The bootloader is only needed for potential later upgrades in the field.

2) How is it even possible that the third command succeeds, when the second command has supposedly locked the bootloader section?

Thanks for your help!


you have to use the -D parameter, this is save writing and bootloader is still there

avrdude -p m328p -b 115200 -c avrispmkii -u -V -P usb:%1 -D -U flash:w:mycode.hex:i