Change Bootloader to Track Reset Flags


I'm trying to use a watchdog timer but while reading the ATMEGA datasheet, I became interested in also tracking when the Yun resets by reading the MCUSR. I have since read through the forums and found that the bootloader prevents this by setting the MCUSR to zero during boot.

I read a potential fix here to change the "MCUSR = 0;" line in the bootloader: Bootloader and MCU reset register - Microcontrollers - Arduino Forum

I also read that the Linux side of the Yun loads the bootloader when updating the sketch over the network which makes it possible to change the bootloader
"If you upload it over the network (either using the IDE, the web interface, or by manual commands using SSH) you are first combining the sketch with the bootloader into a combined image, and then running avrdude on the Linux processor."

I'm running out of reliable information sources (limited documentation) and would appreciate any advice. I'm mostly needing more information about how to upload a new bootloader over the network through the IDE. If someone already did this that would be perfect. In the end, I want to know why my Yun has reset (watchdog, brown-out, etc). If I can fix the bootloader issue, I'm planning on modifying the code here to read the MCUSR


I'm mostly needing more information about how to upload a new bootloader over the network through the IDE.

I don't know that you can do it through the IDE, as it doesn't provide a general purpose way to copy files to the Yun's internal file storage. It does copy some files to the Yun while loading a sketch over the network, but it will only copy the files in the www folder inside your sketch folder to /mnt/sad/arduino//www/ which is not helpful for you.

You will need to use a file transfer utility that supports SCP to copy the compiled bootloader file to /etc/arduino/Caterina-Yun.hex. I use WinSCP and it works well. Or, you could put an SD card in your computer and copy the file to it. Then put the card in your Yun, log into an SSH session, and use the command line to move the file to the right place.

I've seen several threads about updating the Yun's bootloader by replacing this file, but I've never seen feedback on whether it ultimately worked (but I admit I didn't go searching for such results, I've just not seen a reply to the threads I'd been following.) You may be in new territory here. Good luck, and please keep us updated on how it's going and on the final result.