Optiloader Mega2560 support

LuisSoares:
I´am digging though the Optiloader code so i can adapt it to program ATmega2560 to.

Does anyone with experience think the task will be to hard?

I think it should be easy, based on the work I did making a sketch that reads in the flash memory:

The relevant part in my implementation was this function that reads from flash:

byte readFlash (unsigned long addr)
  {
  
  // set the extended (most significant) address byte if necessary
  byte MSB = (addr >> 16) & 0xFF;
  if (MSB != lastAddressMSB)
    {
    program (loadExtendedAddressByte, 0, MSB); 
    lastAddressMSB = MSB;
    }  // end if different MSB
     
  byte high = (addr & 1) ? 0x08 : 0;  // set if high byte wanted
  addr >>= 1;  // turn into word address
  return program (readProgramMemory | high, highByte (addr), lowByte (addr));
  } // end of readFlash

The first few lines switch the "extended address byte" which controls which part of memory you are addressing.

Furthermore the relevant line in the .hex file is here:

:020000023000CC

It is an "02" record which is an "Extended Segment Address Record". This sets the high-order byte of the address to 03 (shifted 4 bits left according to Wikipedia).

So in the next line:

:10E000000D94F6F20D941FF30D941FF30D941FF36E

The address E000 therefore becomes 3E000.

So I suggest that when reading the bootloader, if you hit the "02" record (first line) and change the extended address byte, the rest will just follow automatically.