In light of the ongoing discussion about security during the firmware upgrade process . I would like to add the following explanations: Code exchange between the bootloader and the application will open another door for a potential attack, so you really want to avoid this.
The bootloader part is the part that you really donβt want to change, it should be as static as possible. If the bootloader is broken, field updates become almost impossible, or at least unsafe.
Having said that, you can use a different approach. You can create a maintenance mode for your device. This mode opens the JTAG interface and provides direct memory access. A technician can apply the update.
Now you only need to "activate" the service mode. The following may work: Use the UART interface for activation communication.
- The service system sends its own identifier and requests a service mode through UART
- The maintenance system identifier, a random number, and a unique system identifier are sent back to the service system.
- The service system sends this identification sequence to your certification server.
- If the unique identifier of the system and the identifier of the service system are correct, the server will create a signature of the received information and send it back to the service system.
- Now your system will receive a signature through UART
- Your system verifies the signature against the previously sent public key identification string stored during production.
- Successful verification mode supported
To add security, you definitely want to put some effort into the service identifier, following a similar pattern. The identifier should mainly depend on the MAC address or other unique identifier of the equipment and its signature. The identifier must be created in a safe environment during the production process of the maintenance system. The unique identifier of the equipment must be something visible to the outside world, so the server can really check whether the received ID matches the service system that interacts with the server.
All this setting will give you a secure firmware update without a bootloader. To have reliable firmware updates, a common understanding is that you need an authentication system based on asymmetric encryption such as RSA. If you still need a confirmation code, then the above will exchange a bootloader that can receive updates using the simple UART interface, saving some resources in this process.
Is this what you were looking for?
The commercial bootloader in my experience uses 4 to 8k flash memory depending on the flash algorithm and several other things. I adhere to the same supplier throughout my career, so this may differ from your experience.
Optimized for embedded systems, the digital signature system uses approximately 4.5 kB of flash memory (for example, see https://www.segger.com/emlib-emsecure.html here) and no more RAM than the stack.
You see that 12k is really very low in terms of having a system that can be reliably updated in the field. And even more so if you want the system to be updated using the bootloader.