Thanks for sharing!
I’ve been involved with this SD bootloader project for AVR:
GitHub - zevero/avr_boot: Arduino Bootloader to Flash from SD Card
It’s not at all lightweight and uploading via serial is not officially supported (though a PR was submitted to add this), so yours sounds quite superior. That said, what avr_boot does have going for it is that it’s very accessible to the average Arduino user. Many will gladly trade a few kB of flash for ease of use.
I’d love to see a superior alternative to avr_boot that still has an Arduino-style user-friendly focus, especially since the owner of the avr_boot repository seems to have mostly abandoned that project.
My SD bootloader for the TI parts is intended for products that will need the ability to update firmware, and which can include a microSD port in the design. Also, some of the less expensive chips have very little flash memory to work with, and even less ram, so size could matter a lot. But I don’t know how often you would see an Arduino-based product being used by someone who doesn’t also have the IDE installed, so maybe the typical user would just use serial. In any case, it appears your bootloader is there for those who need the SD functionality. I’m very new to Atmel and Arduino, and not competent to be writing bootloaders. I just thought that the magic number for bootloader size was 2K, and I was wrong about that, but wanted to make the point that it might be possible to do a version of SD in about 1K, which would leave room for Optiboot within the old 2K bootloader size.
My code is small mainly because I implement only what’s absolutely needed for the SD card and for FAT. And I impose some restrictions to help with that. The one that still bothers me a bit is that a file has to be stored in consecutive sectors on the drive. I don’t implement any cluster chaining since many of the TI processors don’t have enough ram to bring in much of the FAT table. The most I bring in at a time from any sector is 64 bytes, and the actual firmware update is written one byte at a time as the bytes come in from the SD card. I don’t know how much of this would be relevant with the Atmel chips.
It occurred to me last night that another difference between the two systems is that the TI chips are 16-bit vonNeumann, which may allow the code to be considerably smaller than AVR. Don’t really know for sure.
With respect to the other comments, my TI bootloader and your avr_boot aren’t the same thing as a separate SD-based programmer. An SD bootloader eliminates the need for such a device.
In case I want to pursue this further, can you tell me how you use the IDE to write a bootloader? Do you just not use the setup() and loop() routines so you get pretty much pure code without all the background Arduino stuff? I was thinking it might be possible to write my code in C++ for Energia, and just see how much size difference it makes, then use the same C++ code in the Arduino IDE, if that’s possible, and see what that produces size-wise. I have a feeling both would be a good bit larger than 1K.