0

Change the Trinket M0 bootloader to only run when the reset
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Change the Trinket M0 bootloader to only run when the reset

by e4st on Thu May 23, 2019 6:47 pm

I am working on a project that requires disabling flashing the Trinket M0 over USB. I want to disable circuitpython, makecode, and anything except the Arduino bootloader (seeing as I am using the Arduino IDE).

This project essentially uses the Trinket M0 as a keyboard emulator, and end users should not be able to flash the Trinket from the computer it is doing keyboard emulation on. This is for security reasons.

Ideally, I want to completely disable flashing over USB except when the reset button is pressed.
Someone has already modified the Adafruit Pro Trinket bootloader to do this (see first answer), I just want the same thing for the Trinket M0.

To avoid confusion: I want just the Arduino bootloader. I want to strip everything else out, and I only want it to be able to be flashed when the reset button it pressed.

If it is not possible to only enable USB flashing when the reset button is pressed, is it possible to disable flashing over USB completely and flash it via the pins?

Conceptually, this is very similar to this project. In the case of Hoodloader2, they are disabling flashing over USB so they can do keyboard emulation on an Arduino Uno/Mega.

Anyone have any recommendations about how to go about this?

e4st
 
Posts: 2
Joined: Thu May 23, 2019 6:29 pm

Re: Change the Trinket M0 bootloader to only run when the re

by danhalbert on Fri May 24, 2019 11:18 pm

You can build your own version of the UF2 bootloader, and turn off various features of it. You can even reduce it to flashing over UART only (we haven't tried that). The source code is here: https://github.com/adafruit/uf2-samdx1. Or you could modify it so that it checks the values of certain pins and doesn't appear unless you have some magic combination you chose.

You could also replace the UF2 bootloader with the SAM-BA bootloader. This guide might help: https://learn.adafruit.com/compiling-m0 ... bootloader. Also this: https://learn.adafruit.com/how-to-progr ... -m0-wiring

danhalbert
 
Posts: 1707
Joined: Tue Aug 08, 2017 12:37 pm

Re: Change the Trinket M0 bootloader to only run when the re

by e4st on Sat May 25, 2019 7:34 pm

Thank you for your help, it is much appreciated.

As far as modifying the UF2 bootloader is concerned, are there any projects that have done this which I can reference? I understand that my particular use case probably doesn't exist, but it would be useful to be able to consult projects which have done similar things.

Also, is there any particular reason to use SAM-BA over UF2? My initial impression is that UF2 has better documentation, but are there particular benefits for one or the other besides that?

e4st
 
Posts: 2
Joined: Thu May 23, 2019 6:29 pm

Re: Change the Trinket M0 bootloader to only run when the re

by danhalbert on Mon May 27, 2019 5:58 pm

This is a simple change to the UF2 bootloader: you're going to change some compile settings in https://github.com/adafruit/uf2-samdx1/ ... /inc/uf2.h. I'd warn you that some combinations may not have been tried, so you might need to a little debugging, e.g. https://github.com/adafruit/uf2-samdx1/issues/51 (which was fixed).

SAM-BA is the default Arduino bootloader, so it works just fine for that (and nothing else). Otherwise, there's no particular advantage.

danhalbert
 
Posts: 1707
Joined: Tue Aug 08, 2017 12:37 pm

Please be positive and constructive with your questions and comments.