I am writing an ethernet capable bootloader for an AVR ATmega328 MCU. I am currently running over the 4k size limit and need some design advice.
- Needs to be able to update the application via a simple UDP based messaging protocol (similar to TFTP).
- As the device operates in a variety of LANs, it should support DHCP.
With my current code, I need about 4k for the Ethernet driver, DHCP, ARP and UDP support. Plus 1.5k for the actual messaging and app programming.
Compiler optimizations are turned on.
My current considerations to proceed are:
- The code is not particularily optimized, so I guess I could save some bytes by following AVR035. I doubt I can save enough code size going this route though.
- I could simply extend the bootloader area by reserving 2k from the top app memory area for the bootloader. I need to be extra careful then to not overwrite that area when programming though. And, I would end up with a large, complex bootloader which probably has bugs, which I cannot update in the field.
- I could move some functions from the bootloader to the app. DHCP could be a good candidate: The app obtains a IP address via DHCP and stores it into EEPROM. The bootloader then can simply use the stored IP address and does not need to do DHCP itself. This could be dangerous though if the app fails e.g. by software bug or random corruption.
Which route would you suggest? Are there other ideas I should consider?