I updated Nick's file to provide some options for what to do with the boot fuses, mostly the 2nd half of this, but I copied the whole function where the fuse is written. Maybe the original program can be similarly tweaked.
The variable BOOTABLE is created by reading a button press after startup.
// returns true if error, false if OK
bool updateFuses (const bool writeIt)
{
Serial.println F(("updateFuses"));
unsigned long addr;
unsigned int len;
byte fusenumber = currentSignature.fuseWithBootloaderSize;
// if no fuse, can't change it
if (fusenumber == NO_FUSE)
{
// ShowMessage (MSG_NO_BOOTLOADER_FUSE); // maybe this doesn't matter?
return false; // ok return
}
addr = currentSignature.flashSize;
len = currentSignature.baseBootSize;
if (lowestAddress == 0)
{
Serial.print F(("lowestAddress = 0, fuse = "));
fuses [fusenumber] |= 1; // don't use bootloader
Serial.println (fuses [fusenumber], HEX);
}
else
{
byte newval = 0xFF;
if (lowestAddress == (addr - len))
newval = 3;
else if (lowestAddress == (addr - len * 2))
newval = 2;
else if (lowestAddress == (addr - len * 4))
newval = 1;
else if (lowestAddress == (addr - len * 8))
newval = 0;
else
{
ShowMessage (MSG_BAD_START_ADDRESS);
return true;
}
Serial.print F(("newval "));
Serial.println (newval, HEX);
if (newval != 0xFF)
{
{
newval <<= 1; //
fuses [fusenumber] &= ~0x07;
fuses [fusenumber] |= newval;
Serial.print F(("newval "));
Serial.println (newval, HEX);
} // if valid
} // if not address 0
}
if (writeIt)
{
Serial.println F(("writeIt"));
writeFuse (fuses [fusenumber], fuseCommands [fusenumber]);
// variation to set fuses based on BOOTABLE
// = 1 is bootloader not run (set LSB to 1), = 0 is bootloader run (clear LSB to 0)
//TLZ - 09/13/16 - force new values into fuses for ATMEGA2560
// Modified 1/29 for boot/no boot
if (strcmp (currentSignature.desc, "ATmega2560") == 0)
{
if (BOOTABLE == 1) {
Serial.println F(("2560 no bootloader in writeIt"));
writeFuse (0xFF, writeLowFuseByte); //
writeFuse (0xD9, writeHighFuseByte); // low bit set
writeFuse (0xFD, writeExtendedFuseByte); //
}
else { // BOOTABLE = 0
Serial.println F(("2560 bootloader in writeIt"));
writeFuse (0xFF, writeLowFuseByte); //
writeFuse (0xD8, writeHighFuseByte); // low bit clear
writeFuse (0xFD, writeExtendedFuseByte); //
}
}
if (strcmp (currentSignature.desc, "ATmega328P") == 0)
{
if (BOOTABLE == 1) {
Serial.println F(("328P no bootloaderin writeIt"));
writeFuse (0xFF, writeLowFuseByte);
writeFuse (0xDF, writeHighFuseByte); // low bit set
writeFuse (0xFD, writeExtendedFuseByte);
}
else { // BOOTLOADER = 0
Serial.println F(("328P bootloader in writeIt"));
writeFuse (0xFF, writeLowFuseByte);
writeFuse (0xDE, writeHighFuseByte); // low bit clear
writeFuse (0xFD, writeExtendedFuseByte);
}
}
if (strcmp (currentSignature.desc, "ATmega1284P") == 0)
{
if (BOOTABLE == 1) {
Serial.println F(("1284P bootloader in writeIt"));
writeFuse (0xF7, writeLowFuseByte);
writeFuse (0xDF, writeHighFuseByte); // low bit set
writeFuse (0xFD, writeExtendedFuseByte);
}
else {
Serial.println F(("1284P no bootloader in writeIt"));
writeFuse (0xF7, writeLowFuseByte);
writeFuse (0xDE, writeHighFuseByte); // low bit clear
writeFuse (0xFD, writeExtendedFuseByte);
}
}
}
return false;
} // end of updateFuses