Bootloader for SAMR21 to work with Arduino IDE


I am trying to make my SAMR21 XPLAINED Pro board work with Arduino IDE but no luck so far.
I found a SAMD21 bootloader for Arduino M0 and I modified it to have the corresponding R21 libraries, but it doesn't work, it reads part of the messages it receives and keeps restarting after a few seconds.

I would appreciate it if you could point me to the right direction here, I can't find any documentation for the M0 bootloader to see how it should work and the ASF is quite nested for a beginner.