Some of you may know Barebox, others may be more familiar with its pre-fork, U-Boot. Both do one thing very well: being a bootloader for your embedded Linux stack.
Looking like a shell-like environment, Barebox has basic commands available to boot a system from a variety of sources (flash, USB, SD, SATA, network, ...). Small embedded systems will very often boot using a network source which would require only a networking stack and no storage memory.
Barebox contains networking features, but it is missing a fully fledged network stack. Unfortunately its ICMP implementation is unable to handle pings which can be a quick first line of network debugging for a developer. Having an embedded devices bootloader that supports many networking protocols can improve the capability of the device itself such as getting data from an HTTP webserver. But it doesn’t have to end there.
At some point we have to stop reinventing the wheel and just look for a solution that does it all for us. That is when the Barebox community discovered picoTCP. It features everything a successful bootloader needs. picoTCP has a small codebase with TCP capabilities, is IPv6 ready and can easily be configured to optimize for a combination of size, speed and features.
While designing picoTCP we hadn’t planned for it to be included into a Linux bootloader. However, the Barebox community managed to do just this in a very short amount of time. At that point the picoTCP and Barebox developers have been working together to integrate every aspect of the stack. One such effort resulted in blocking calls on bare metal devices, even when there is only one thread available. Over time an extensive API library saw the day of light and entirely new features were developed as well such as..
Supporting file transfers with TFTP
Trivial File Transfer Protocol was a necessity for Barebox so picoTCP promised and delivered. Since picoTCP is extremely adaptable, incorporating TFTP was a breeze. In a matter of days the protocol was written and tested to work according to its specifications.
picoTCP gives you, the developer, TFTP support with little to no effort on your side. Booting and receiving updates from the network has never been easier when working with embedded devices. TFTP is probably the standard for most of the devices that somehow boot or get their updates from a local network. TFTP runs on top of UDP and has some basic acknowledge mechanism to make sure packets arrive at the destination.
A “client” (see picture below) is really easy to make: provide pico_tftp_start_rx with a callback and you’ll get the packets sent right to your callback routine. This is exactly how Barebox is using picoTCP.
You can also run a “server” (see picture below) so clients can connect to it and retrieve files. pico_tftp_listen allows you to provide an address, a filename and a callback. Whenever a client asks for that combination, the callback can execute a pico_tftp_start_tx and then start to pico_tftp_send chunks.