I'm currently adapting Optiboot to a previously unsupported board using ATmega8535. I'm currently struggling with the fact that it only lets reprogram itself once (via the bootloader). I've been searching for the answer and found out that it might be related to wrong lock bits, lock bits that prevent overwriting the bootloader. Avrdude informs me that there are some issues with lock bits at the end of burning the bootloader:
avrdude: writing lock (1 bytes):
Writing | CMD: [58 00 00 00] [04 58 00 ff]
CMD: [ac e0 00 cf] [00 ac e0 00]
CMD: [58 00 00 00] [cf 58 00 ff]
CMD: [58 00 00 00] [00 58 00 cf]
CMD: [58 00 00 00] [00 58 00 cf]
CMD: [58 00 00 00] [00 58 00 cf]
CMD: [58 00 00 00] [00 58 00 cf]
CMD: [58 00 00 00] [00 58 00 cf]
***failed;
So what I've understood is that with wrong lock bits when reprogramming via the bootloader there's a possibility to overwrite to bootloader, but it doesn't make sense: Optiboot is 512 bytes and stored at the very end of flash memory according to the datasheet, my program is about 1KB and written at the beginning, the available memory is 8KB, how can my program rewrite the bootloader section if it cannot reach it?