I have an Arduino MCU with bootloader already programmed in. If I want to program new firmware using ISP interface, will the bootloader be erased? Can the new firmware be programmed in without erasing the bootloader?
Aye. Nay.
The two images can be combined by hand.
If the memory space of the "new firmware" overlaps with that of the bootloader, the bootloader will be at least partially overwritten.
jremington:
If the memory space of the "new firmware" overlaps with that of the bootloader, the bootloader will be at least partially overwritten.
Is there some way to make sure that the memory space of the new firmware doesn't overlap with that of the bootloader? When I write sketches, I don't really bother about memory spaces.
jremington:
If the memory space of the "new firmware" overlaps with that of the bootloader, the bootloader will be at least partially overwritten.
You imply that first erasing the target is not necessary. Which further implies the upload will be corrupt.
@lightaiyee, the accurate reply is #1. The target has to be erased, including the bootloader, before uploading using ISP.
Programming has to erase the former contents of the flash area it needs to reprogram.
Self-programming (as used by the bootloader) can erase one flash page at a a time, but ISP programming can only erase the ENTIRE flash memory.
Therefore, using ISP programming ALWAYS erases the bootloader, even if the code you are programming does not overlap the memory area used by the bootloader.
(of course, if you are using ISP programming, it's easy to put the bootloader back.)
Good to know, but then aren't the fuses set to expect a bootloader to be present and run at startup?
lightaiyee:
Is there some way to make sure that the memory space of the new firmware doesn't overlap with that of the bootloader? When I write sketches, I don't really bother about memory spaces.
Well now, the answer is you need to bother.
The bootloader will not permit itself to be overwritten (if properly written, it simply cannot.) So loading via the bootloader will not do that, but lose any code that would overlap the bootloader.
If you want to use ISP, you really need a two-step process. You generate your Hex file, examine it (visually) to ensure it does not overlap the bootloader area, then splice the bootloader code to it and burn that to the chip in one go.
SukkoPera:
Good to know, but then aren't the fuses set to expect a bootloader to be present and run at startup?
Yes. The fuses need to be changed to match the fact that the bootloader is no longer present.
You imply that first erasing the target is not necessary. Which further implies the upload will be corrupt.
Sorry I didn't cover all the bases, as you did by answering "Aye. Nay."!
Two questions asked. Two accurate answers provided. Bases covered.
Please try to stay on topic. The topic at hand is provided at the top.
Stop sniping.