Export .hex with bootloader for ATtiny85Core (Spence Konde

How can a hex file with bootloader be generated and saved for an ATtiny board?

The boards.txt file by Spence shows following relevant part:

attinyx5opti.name=ATtiny45/85 (Optiboot)
attinyx5opti.upload.tool=avrdude
attinyx5opti.upload.protocol=arduino
attinyx5opti.upload.speed=19200
attinyx5opti.bootloader.tool=avrdude
attinyx5opti.bootloader.unlock_bits=0xFF
attinyx5opti.bootloader.lock_bits=0xFF
attinyx5opti.bootloader.file=optiboot/optiboot_{build.mcu}_{build.f_cpu}.hex
attinyx5opti.build.core=tiny
attinyx5opti.build.board=AVR_ATTINYX5
attinyx5opti.build.export_merged_output=false
attinyx5opti.bootloader.extended_fuses=0xFE

The relevant part in his platform.txt file shows:

## Save hex
recipe.hooks.savehex.presavehex.1.pattern.windows="{runtime.platform.path}/delete_merged_output.bat" {build.export_merged_output} "{build.path}\{build.project_name}.with_bootloader.hex"
recipe.hooks.savehex.presavehex.2.pattern.windows=cmd /C copy "{build.path}\{build.project_name}.lst" "{sketch_path}"
recipe.hooks.savehex.presavehex.1.pattern.linux=chmod +x "{runtime.platform.path}/delete_merged_output.sh"
recipe.hooks.savehex.presavehex.2.pattern.linux="{runtime.platform.path}/delete_merged_output.sh" {build.export_merged_output} "{build.path}/{build.project_name}.with_bootloader.hex"
recipe.hooks.savehex.presavehex.3.pattern.linux=cp "{build.path}/{build.project_name}.lst" "{sketch_path}"
recipe.hooks.savehex.presavehex.1.pattern.macosx=chmod +x "{runtime.platform.path}/delete_merged_output.sh"
recipe.hooks.savehex.presavehex.2.pattern.macosx="{runtime.platform.path}/delete_merged_output.sh" {build.export_merged_output} "{build.path}/{build.project_name}.with_bootloader.hex"
recipe.hooks.savehex.presavehex.3.pattern.linux=cp "{build.path}/{build.project_name}.lst" "{sketch_path}"

recipe.output.tmp_file={build.project_name}.hex
recipe.output.save_file={build.project_name}.{build.variant}.hex

But when I try and export the compiled binary, following text shows in verbose output at the end of the compiled output:

C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.2.3/delete_merged_output.bat false C:\Users\ERIKAR~1\AppData\Local\Temp\arduino_build_329590\ATtiny_Analog_Write.ino.with_bootloader.hex 
cmd /C copy C:\Users\ERIKAR~1\AppData\Local\Temp\arduino_build_329590\ATtiny_Analog_Write.ino.lst C:\Users\Erik Arckens\Google Drive\documents\Arduino\ATtiny_Analog_Write 
        1 file(s) copied.

The ATtiny doesn't have room for a bootloader. The only thing the "Burn Bootloader" operation does on an ATtiny is to set the configuration fuses. Since there is no bootloader, there is no way to include it in the sketch binary.

1 Like

Strange, how do you explain the working of the virtual USB on a Digispark? Micronucleus and Optiboot are ATtiny bootloaders. If I have a ATtiny that I want to connect a USB connector to then a bootloader is required.

Solved!
The ATtiny85 does indeed have room for a bootloader: micronucleus which is used by Digispark to allow USB connection for their ATtiny85 based boards.
However, what I was looking for is to load both code and bootloader with a single hex file.
Now that is superseded by downloading the micronucleus bootloader in a fully erased ATtiny85 with a USBtinyISP or its chinese clone . Then with AVRDUDESS , which is a userfriendly GUI for avrdude, this hex file can be programmed in an ATtiny.

Thus bypassing the need for a combined code+bootloader hex file.