I'm working on a project of remotely operated astronomic observatory, and in the scope of this project I needed many TCP/IP controlled boards.
As I'm familiar with networks environements the availability of a working and reliable TFTP bootloader was really missing to the Arduino boards in my point of view.
So I decided to rewrite the code of the unachieved TFTP bootloader published by the Arduino team, and since a few weeks I have a bootloader that works correctly and helps me in my work on the Arduino boards in development environment and production.
As I think this feature is very nice (fast, reliable and network oriented) I think it is interesting to publish it, and maybe to add a feature in the IDE in order to program the Arduino directly trough TFTP.
Actually you can download it from this website:
http://harizanov.com/wp-content/uploads/2012/03/TFTPBootLoader_0_2.zip
Github: https://github.com/mharizanov/TFTPBootloader_0_2
This bootloader starts a TFTP server on default UDP Port 69, and listens for about 5 seconds at startup. During this time the user can upload a new firmware using any TFTP client software.
It manages interrupted file transfers even if a power failure succeed.
At this time the bootloader's size is about 1500 words (3000 Bytes). Fuses have to be configured in order to declare a 2Kwords booloader.
Therefore the user code must not exceed 28672 Bytes.
At this time the bootloader has only been tested on Arduino Ethernet, but the source code can easily be adapted to other boards.
The code to be modified is:
#define SCK_PIN 5 //PB5 #define MISO_PIN 4 //PB4 #define MOSI_PIN 3 //PB3 #define SS_PIN 2 //PB2
#define LED_PIN 1
There is only one supported ethernet controller, the W5100.
Bytes 0 to 20 are reserved for the TFTP Bootloader, please read "Settings stored in flash" below
Connect a TinyUSB programmer and "make install".
The bootloader accepts raw binary images, starting at address 0x0000.
These can be generated using avr-objcopy, part of WinAVR / AVR-GCC, using the "-O binary" option.
Example: avr-objcopy -j .text -j .data -O binary [firmware].elf [firmware].bin
When using the Arduino IDE you will need to make a verbose compile of your sketch and then check in the temp directory use for the .elf file freshly generated.
Rapid blinking: Ethernet bootloader is wainting for a connection.
This TFTP bootloader does not implement a DHCP client at this time. As it has been thought to be as tiny, reliable and autonomous as possible only static addressing is supported.
DHCP boot with TFTP server address recovery in specific DHCP Option could be an option in order to have a diskless station like behaviour, but once again this bootloader has been thought to be rock-solid and automatic flashing of firmware at startup is a dangerous option.
In order to provide the possibility to configure the Ethernet settings used by the TFTP Bootloader and the user application, the following settings can be stored in the MCU flash.
These are intended to be shared between the TFTP Bootloader and the client App. This will avoid any inconsistencies and ARP resolution problems during the initialisation process that would succeed if different MAC addresses are used for example.
The consistency of these settings have to be garanteed by the client application.
The following error codes and error strings can be reported to the TFTP client software:
Debugging can be enabled at time of compilation in debug.h, uncomment the following line, save and compile:
//#define DEBUG
should be replaced by :
Debug will be outputted to the serial port of the Arduino board at 115200 bps speed.
For any questions you can contact me at denis dot perotto at gmail dot com