I was able to take 224 bytes off the size of the firmware, bringing it well below 2.0k.
First, some background on the changes. When I made
USBasploader-tiny85, one of the goals was to use existing software on the PC to interact with the boot loader, with very little PC software modifications. This meant putting a lot of intelligence into the boot loader. After I saw the result was a huge 2.6k boot loader, and later saw micronucleus close but not quite at 2.0k with a much simpler protocol, I realized that for this project the firmware should be made as simple as possible. I stepped back and looked at what the firmware was doing, and thought about moving as much as possible to the PC side.
The main things moved to the PC side are the calculation of the vectors stored in flash, and intelligence on when to use the Page Erase and Page Write SPM instructions. The firmware no longer knows how to erase the application or even erase a page, it just knows how to execute a generic SPM programming sequence. The PC software sends it commands with details on how use SPM to erase a page and to write a page to flash while running.
These changes brought the firmware below 2.0k, and I was able to make the page loading code a little more space efficient too, at the cost of speed. Instead of sending a full page of data at once to load into the buffer, a shorter message with just a word at a time is sent instead, saving about 50 bytes of flash. Transferring data this way is slower, and it takes about a second longer to program, but the code is small enough to give another page of flash back to the application. After these changes the boot loader can start at address 0x1880, two pages (128 bytes) smaller than the 2.0k goal.
I originally did all my work using the latest version of AVR CrossPack, but used the old 20100115 version which compiles a smaller binary for the final commits. It's only 8 bytes more efficient with this new firmware, but that's enough to move the boot loader across a page boundary, so it's still worth releasing code with the old toolchain.
Pull request on github here:
https://github.com/Bluebie/micronucleus-t85/pull/21I'm working on a version of the boot loader that uses the HID interface so no windows drivers are needed, and communication can be done through native libraries instead of libusb. Adding HID takes a firmware size hit, it's about 200 bytes larger, so I doubt it will be of interest here, but just in case, here's the branch where I have some initial working code:
https://github.com/embedded-creations/micronucleus-t85/tree/HIDThanks to Bluebie for the great ongoing work on micronucleus and ihsan for the commandline utility!