Arduino USB DFU firmware from scratch
This post documents how you can build from scratch DFU firmware using Atmel Studio 7 and its LUFA Library extension. You’ll need an ISP/ICSP programmer to program the ATmega16U2.
You can install the LUFA extension from the Extensions and Updates dialog (Tools -> Extensions and Updates).
Create a new project based on the DFU Bootloader example (File -> New -> Example Project…).
Change the compiler optimization setting to -Os in toolchain properties (Project -> Properties).
Build the solution and flash (Tools -> Device Programming) using an ISP/ICSP programmer connected to the ICSP2 header.