I am on my path to write my first bootloader.
Q.1 One question is do you erase all the flash memory before writing? Or just enough pages which the next application will occupy? What is the norm?
Q.2 If I don't erase all the flash memory, can the left over code from the previous application interfere with the new application code in any way?
Out of curiosity, I tested the arduino bootloader, it seems to me that arduino bootloader does not erase all the flash memory before the next sketch upload, previous application data still lives (obviously this will only happen when the new application data size is less than the previous application data size). So this kinda answer's my question 2, if arduino is not erasing it then it must be okay. Right?
Note - The application for which I am writing bootloader for, the end user will be flashing new hex very frequently over USART, so for one day it might only take 5-6KB of space but for some other it might take 30KB of space. So what do I do? I am confused, bootloader should erase all the memory or just enough to get the job done?
I mean it is safer to go with "erase all the memory" but then why arduino people didn't do it? Is there any benefit to it.