Does anybody know any resources about programming custom bootloaders for Arduinos / AVR chips?

1kB TFTP Bootloader for AVR / ENC28J60

Another option, although a bit extreme, is to connect the arduino to a raspberry pi, then remotely log onto the pi and run the IDE from there.

Considering that bootloaders use size saving techniques and use macros in the middle of code, I'd say that they do take a departure from regular programming techniques where at most you would add header guards, include libraries, and possibly use #define for const variables. Thank you for the resources, though, I didn't notice that optiboot had a wiki

Well, if you have specific questions about how Optoboot works, I'll be happy to try to answer.


I would opine that the bootloaders are more like typical C than most Arduino sketches. Arduino sketches are for a variety of reasons both cultural and technical, "easy-mode C++". (C does not have classes, function overloading, or default values for arguments). Cultural as in, most arduino sketches are written by less experienced programmers who don't know the more esoteric and advanced features of the languages (and classes are rarely defined except in libraries), and technical because among other things, the IDE generates function prototypes for you, and it's an embedded system where certain other features of the language are impractical, unavailable, or strongly discouraged. Bootloaders on the other hand, with the extremely tight space constraints... those are hard mode C

Every bootloader I've worked on (modifications to two versions of Optiboot, and then porting one of them to the new NVM controller on the Dx-series parts to make a third, ChipBoot, the mega2560 bootloader whatever that's called, and Micronucleus) was written in C. The only assembly amounting to more than a line or two was written by yours truly, as I desperately tried to get the 128k Dx-series bootloader to fit into 512b of flash while still ensuring that it would handle a dirty reset or jump to 0 gracefully and honor entry the entry conditions specified when it was compiled). The Dx-series optiboot (distributed as part of DxCore) is the only one of those six that has anything I would characterize as bizarre in it. the porting from modern tinyAVR to Dx was all my doing. and the flash was tight enough that I had little maneuvering room to write nicer code, . I would recommend like, not picking that one to study. :wink:

But they are a LOT less weird if you have experience reading and writing extremely low-level libraries, instead of just sketches.