set DFU_SERVER_COM_PORT=COM3
set DFU_SERVER_DK=683583355
set CLIENT_DK_SNR=683825227

::Comment in the next lines to generate new set of keys:
::del ..\..\dfu\dfu_public_key.c
::del ..\..\dfu\private.pem
::nrfutil keys generate ..\..\dfu\private.pem
::nrfutil keys display --key pk ..\..\dfu\private.pem --format code --out_file ..\..\dfu\dfu_public_key.c

cd ..\..\..\external\micro-ecc\
call build_all.bat
cd ..\..\examples\thread\dfu

make -j9 -C bootloader\pca10056\blank\armgcc
make -j9 -C client\pca10056\blank\armgcc 
make -j9 -C ..\ncp\ftd\uart\pca10056\blank\armgcc\

del files\settings.hex
nrfutil settings generate --family NRF52840 --application client\pca10056\blank\armgcc\_build\nrf52840_xxaa.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 files\settings.hex
del files\dfu_client.hex 
mergehex -m client\pca10056\blank\armgcc\_build\nrf52840_xxaa.hex files\settings.hex -o files\dfu_client.hex 

nrfjprog -e --snr %CLIENT_DK_SNR%
nrfjprog -e --snr %DFU_SERVER_DK%

nrfjprog --program ..\..\..\components\softdevice\mbr\hex\mbr_nrf52_2.4.1_mbr.hex --verify --snr %CLIENT_DK_SNR% 
nrfjprog --program bootloader\pca10056\blank\armgcc\_build\nrf52840_xxaa_mbr.hex --verify --snr %CLIENT_DK_SNR% 
nrfjprog --program files\dfu_client.hex --verify --snr %CLIENT_DK_SNR% 
nrfjprog --reset --snr %CLIENT_DK_SNR%

del files\app_dfu_package.zip
nrfutil pkg generate --hw-version 52 --sd-req 0x00 --application-version 2 --application files\app_3.hex --key-file ..\..\dfu\private.pem files\app_dfu_package.zip 


nrfjprog --program ..\ncp\ftd\uart\pca10056\blank\armgcc\_build\nrf52840_xxaa.hex --verify --snr %DFU_SERVER_DK% 
nrfjprog --reset --snr %DFU_SERVER_DK%
TIMEOUT 5
nrfutil dfu thread -pkg files\app_dfu_package.zip -p %DFU_SERVER_COM_PORT% --channel 12 --panid 43981 

