Bootloader Differences

  1. Why are there two folders named arduino-usbdfu and arduino-usbserial in the Arduino Firmwares folder? What is different in those 2 versions?

The usbdfu is the (USB) Bootloader for the 16u2, so that you could load new firmware onto that chip.
The usbserial code is the "application" for the 16u2, that does the USB/Serial conversion.
(Note that neither of these is the bootloader for the Arduino AVR itself (the m328 or m2560.) Those are in the "bootloaders" directory.)

  1. In say Arduino Uno or Mega, from my understanding, the onboard Atmega16u2 chip is just for USB to serial conversion between PC and the Atmega328 or Atmega2560 chip. Or does it do something else too?

It CAN be loaded with firmware that allows the Arduino to appear as other types of USB devices (keyboard, mouse, MIDI port, gamepad, etc.) At one time, this was expected to be important, but I think it has fallen behind boards like the Micro and Leonardo that can support such applications in a more obvious fashion.

  1. Is there a tutorial or writeup somewhere on how to go about writing a Arduino bootloader(for a new chip) because I really would like to know the process?

[http://www.avrfreaks.net/forum/faq-c-writing-bootloader-faq?skey=bootloader%20tutorial](http://"http://www.avrfreaks.net/forum/faq-c-writing-bootloader-faq?skey=bootloader tutorial")
In addition, Atmel has some App Notes (AVR109 being famous?) and a lot of the bootloaders are open-source, so you can look at them. The overall outline is pretty simple:

  1. figure out how to start the bootloader.
  2. Read the file to be programmed from "somewhere."
  3. Write the data to flash using the self-programming feature and "SPM" instruction (for AVRs, anyway.)
  4. figure our how to exit the bootloader and start the application code.