kayahr
kayahr

Reputation: 22010

How to replace the bootloader of an ATMEGA88

I have a board with an ATMEGA88 chip which has a bootloader at address 0x1800 and a firmware at address 0x0000. Both have access to USB. The bootloader can write a new firmware but now I need to write a new bootloader.

Sure, this is no problem when using the AVR programmer but is it also possible to do this via USB? My idea was flashing a special firmware via the old bootloader which then can write a new bootloader. Is that possible? If yes, how?

My current tries were not successfull. All commands (boot_page_erase, boot_page_fill and boot_page_write) are executed successfully the same way as the bootloader is doing it (only difference is that it starts writing at index 0x1800 and not 0x0000) but when I restart the device then the old bootloader is still there so nothing was really written to the flash.

Upvotes: 1

Views: 1335

Answers (2)

Lars Noschinski
Lars Noschinski

Reputation: 3667

The memory of the ATmega88 is divided into two sections, Read-While-Write (RWW) and Non-Read-While-Write (NRWW). Only from the NRWW-section it is possible to execute the SPM command (if executed from the RWW section, it silently fails). See section 2.2 (page 6) of the datasheet. The NRWW section is equivalent to the biggest possible bootloader section.

So, to reprogram the bootloader using the SPM instruction, you need to have at least a minimal stub of code in the bootloader section, which you do not delete and which executes the SPM instruction for you.

Upvotes: 1

lImbus
lImbus

Reputation: 1588

It's been a while since I played with AtMega, but it would seem logical to me that if the bootloader does not support repplacing the bootloader (question of prudence) or touch the memory around that, that then you would not be able to geflash the bootloader through the bootloader.

You would then have to write a firmware that (very much like a bootloader) rewrites the flash.

Upvotes: 0

Related Questions