nielsreijers/NanoKong — Issue #7: Arduino bootloader
Author: nielsreijers
Created: 2011-10-20 06:46:50+00:00
State: open

The bootloader erases memory in a very dangerous way. On every write to flash using CMD_PROGRAM_FLASH_ISP, it erases the next page of flash. This assumes that we always write one page of flash at a time, else the erase cycle gets ahead or behind of the flash writes. It also assumes we start writing from adress 0x00 up.

The part I fixed in 9fd27ab44cbd93b7573b6f9bd38e6bcb7218c87e, is to move the erase address to the same address as the write address when CMD_LOAD_ADDRESS is received. (actually the start address of the page containing the write address) Before only the write address was updated, which meant the data got written at the right address, but a completely different page was erased.

This at least allows us to upload different sections of memory, but clearly there are MANY was to make this break down, but at least it's better than what we had before. Avrdude seems to be writing in at most 1 page blocks, so if we program flash starting at page boundaries, and write from lower to higher addresses when multiple sections need to be uploaded, we should be fine.