Hello everyone!
Like the title says, I’m looking to add a bootloader to my project but would like some input since I’ve never done such a thing.
Goal:The goal of the bootloader is to safely update the main program code over the UART. The update should be able to be performed by a PC or by a PLC and should be as easy as to use as possible.
Just send the bytes from the PC, the bootloader responds with "ACK/NACK" if the checksum adds up and then it continues.
Problems:One of the problems is that I’ve never written a bootloader, it does seem quite straight forward and looking at existing ones on GitHub makes it seem rather unremarkable. The thing is that I would prefer a tested bootloader that is known to work well instead of creating one from scratch and possibly introducing bugs that would require a reflash to fix.
The second problem is that the processor (ATMega328P) communicates over RS485 with a RS232 to RS485 transceiver and an extra pin is used for flow control. The processor does not have a hardware configurable flow control pin like most modern processor, so the communication direction must be controlled through software. This is however an easy things to do.
Possible bootloaders:So I’ve done some searching on the internet for possible bootloaders to use but haven’t found a bootloader that would work right out of the box.
OptiBoot seems to be the most robust opensource bootloader, but I don’t like that it is made for Arduino. It emulates the STK500 which is nice but seems rather extensive for what I need, not completely sure how il write an STK500 programming interface for a PLC.
Another downside/upside is that it’s a very extensive bootloader with somewhat lacking documentation that has support for loads of processors and configurations, i just need it to work on one processor and make it as simple as possible to use/understand. At first glance, OptiBoot does not support "custom" entry/calling the bootloader from the main program, something id like to do.
https://github.com/Optiboot/optibootMagBoot is another alternative, its not as commonly used but seems good. Its a very stripped-down bootloader which is nice. I’ve done a re-write of this bootloader to make it work for my application and it seems to work (not done any extensive testing). There are things I don’t like with it so if I decide to go for a custom bootloader il use it as a reference and write one from scratch. This bootloader doesn’t really have any documentation but is small and easy to understand.
https://github.com/blastur/magbootThere are tons of bootloader on the internet so I’m not sure which one to use or if il write one from scratch.
It seems rather unnecessary to write one from scratch and I would like to avoid it so as not to introduce a bug that would require a complete reflash to correct. But id also not want to use a online bootloader that has some bug in it either. I’ve done some searching on the web and in this forum/avrfreaks but haven’t found a definitive answer.
Any input is appreciated!