Optiboot / optiboot

Small and Fast Bootloader for Arduino and other Atmel AVR chips
Other
1.09k stars 401 forks source link

Questions about writing data to flash in bootloader #328

Closed wxutopia closed 2 years ago

wxutopia commented 2 years ago

Do functions boot_page_erase_short() and boot_page_erase() erase an entire flash page?

How can I write any-sized data, like 10 bytes to flash in bootloader?

WestfW commented 2 years ago

The flash logic in the AVR can only erase full pages. If you want to modify a smaller bit of flash, you would have to read the existing flash page into a RAM copy, erase the full page, modify the bytes you wanted to change in your copy, and then write the full page.

(actually, I guess if the flash page contains 0xFF (ie "was previously erased"), you should be able to write new data without erasing the page, as long as you're overwriting only the 1 bits.)

wxutopia commented 2 years ago

The flash logic in the AVR can only erase full pages. If you want to modify a smaller bit of flash, you would have to read the existing flash page into a RAM copy, erase the full page, modify the bytes you wanted to change in your copy, and then write the full page.

(actually, I guess if the flash page contains 0xFF (ie "was previously erased"), you should be able to write new data without erasing the page, as long as you're overwriting only the 1 bits.)

Sounds like a good idea, thanks a lot!