Nordic Semiconductor has some great examples that show the inclusion of the DFU code and creating update files:
Unfortunately, due to different memory location configurations in the UICR, there is no OTA method of switching bootloaders. The SWD port is required. If you are currently using RigDFU and wish to change to Nordic's DFU, you will need to perform a full erase over the SWD port.
You can use the following command line (this assumes you have nRF Connect and the Nordic Command Line Utilities installed):
nrfjprog -f nrf52 --recover
Maintaining MAC Address:
With AD and AE firmware, you can read the MAC address and store it in a file over the J-Link interface, erase the module, then re-program the MAC along with your code, SoftDevice and Nordic DFU.
An example script from our factory programmer utilities that has the MAC read / re-program commands is attached to this article. You can use this as a template. Just change the filenames and memory locations as needed.
In the section where files are being loaded with "loadbin", you can also load hex files with "loadfile". If you use loadfile, though, there is no corresponding "verifybin", but both loadbin and loadfile actually perform a verify as part of the programming process.
The attached file includes hex2bin. Run the following to create a binary file:
hex2bin -c myfile.hex
Full information for hex2bin is here: http://hex2bin.sourceforge.net/
The full J-Link manual is here: https://www.segger.com/downloads/jlink/UM08001
For details on the release of RigDFU source code, please see the follow article: