From: HERE
Hi
I have successfully merged softdevice S110 7.0.0, the bootloader from nRF51 SDK 6.1.0, and application from SDK 6.1.0 with using the mergehex.exe tool. Additionally, the attached app_valid_setting_apply.hex file must be merged into the final .hex file to create valid bootloader settings. The mergehex.exe tool can only merge two files at a time, so you need to merge three times in order to merge together the four .hex files. The procedure is:
- Merge softdevice and bootloader: mergehex -m s110_nrf51822_7.0.0_softdevice.hex bootloader.hex -o SD_BL.hex
- Merge softdevice+bootloader and application: mergehex -m SD_BL.hex ble_app_hrs_dfu.hex -o SD_BL_APP.hex
- Merge softdevice+bootloader+application and bootloader settings file: mergehex -m SD_BL_APP.hex app_valid_setting_apply.hex -o SD_BL_APP_Settings.hex
I attach the files that I merged to gether:
app_valid_setting_apply.hex
ble_app_hrs_dfu.hex
bootloader.hex
s110_nrf51822_7.0.0_softdevice.hex
The following steps are:
- Erase the nRF51 chip: nrfjprog --eraseall
- Program the merged file: nrfjprog --program SD_BL_APP_Settings.hex
- Then power-reset the device
- or combine all three above into one command: nrfjprog --eraseall --program SD_BL_APP_Settings.hex --pinreset
Now the nRF51 device should be advertising as Nordic_HRM. Press Button_7 on the nRFgo motherboard while power-resetting in order to enable bootloader mode, or enable bootloader mode from the central device (buttonless) with the procedure described here in the "Testing" section.
Update 5.12.2014 for gcc compiler If using gcc to compile the bootloader and application the above method will not work. The gcc compiler writes the .hex files a little differently than the Keil compiler. The best method to merge the files when compiling with gcc is to merge the softdevice, bootloader and application with mergehex and then manually add the contents of the app_valid_settings_apply.hex file into the softdevice+bootloader+application merged file. Actually, only line 2 should be copied from app_valid_settings_apply.hex into the correct location of the merged file as shown in the image below:
The "FC00" code in the selected line in the image above represents the flash address the data is written to (see intel hex format) and you should replace the line with the same "FC00" address code in the merged file.
Update 5.12.2014 for 128kB flash (QFAB) nRF51x22QFAB chips have 128kB flash and the above method will not work for those chips. Included below is a new setting file that works for 128kB flash and the bootloader provided on this thread for 128kB nRF51 chips. I include also the other hex files I used for the merge and the three output files. The ble_app_hrs_dfu_16kB.hex is the heart rate example with DFU service, compressed to take only 16 kB. If not compressed, it will take 25kB and will therefore not fit in the application space for the 128kB chip.
app_valid_setting_apply_QFAB.hex
ble_app_hrs_dfu_16kB.hex
bootloader_QFAB.hex
s110_nrf51822_7.0.0_softdevice.hex
SD_BL_APP_QFAB.hex
SD_BL_APP_Settings_QFAB.hex
SD_BL_QFAB.hex
Update 20.4.2015 Flash files seperately It is also possible to upload the files separately without merging them. Flash it in the following order:
s110_nrf51822_7.0.0_softdevice.hex
bootloader.hex
ble_app_hrs_dfu.hex
app_valid_setting_apply.hex
Update 20.4.2015 for softdevice 8 This also works with the same app_valid_setting_apply.hex file for softdevice 8 if you flash first S110 v8 and the bootloader and application from SDK 8.
Update 28.10.2015 Procedure and example files for S110 7 With S110 7 and bootloader from SDK 7, softdevice and bootloader updates were possible with an over the air update. This means that if you have i.e. S110 7 + bootloader from SDK 7, it is possible to update the device over the air (via Master Control Panel for Windows PC or nFR Toolbox app for Android, IOS or Windows phone) to contain S110 8 and bootloader from SDK 8 or SDK 9.
You can merge e.g. the following files with mergehex.exe
s110_nrf51822_7.3.0_softdevice.hex
BL7_1.hex
ble_app_bps_SDK_7_1_0.hex
app_valid_setting_apply.hex
into one file
with the following command sequence:
mergehex --merge s110_nrf51822_7.3.0_softdevice.hex BL7_1.hex --output SD_BL.hex
mergehex --merge SD_BL.hex ble_app_bps_SDK_7_1_0.hex --output SD_BL_APP.hex
mergehex --merge SD_BL_APP.hex app_valid_setting_apply.hex --output SD_BL_APP_valid.hex
and then flash the file onto your nRF51-DK board (PCA10028) using nrfjprog.exe with
nrfjprog --program SD_BL_APP_valid.hex
then the ble_app_bps application should be advertising on your nRF51-DK.
Another method of obtaining the same thing without merging the files is with flashing the 4 files directly with the following command sequence:
nrfjprog --eraseall
nrfjprog --dfu --programs s110_nrf51822_7.3.0_softdevice.hex
nrfjprog --program BL7_1.hex
nrfjprog --program ble_app_bps_SDK_7_1_0.hex
nrfjprog --program app_valid_setting_apply.hex
Update 6.5.2016 If you want to merge nRF52832 hex files into one, then you need to use the following app valid setting file:
app_valid_setting_apply_nRF52832.hex
and merge it together with the softdevice, bootloader and application with mergehex.exe in the same way as has been described for nRF51. I have merged the following hex files with the app_valid_setting_apply_nRF52832.hex file, i.e. S132 2.0.0 softdevice, bootloader and heart rate example from SDK 11.0.0:
s132_nrf52_2.0.0_softdevice.hex
dfu_test_bootloader_b_s132.hex
dfu_test_app_hrm_s132.hex
when they are merged, they create the following combined file that can be flashed directly to the nRF52832:
-
The merge issue was a Windows issue, the OS wasn't giving file write permission to mergehex. Thanks for the help
-
I still cannot seem to merge with the Setting.hex files you provided with my own Bootloader.hex file. ERROR: Merge not possible due to conflict in files. I know the bootloader settings should be set to 0x0003FC00. I believe I have done this properly.
- dfu_types.h - #define BOOTLOADER_REGION_START 0x0003FC00
#define BOOTLOADER_SETTINGS_ADDRESS 0x0003FC00/ Linker script to configure memory regions. / SEARCH_DIR(.) GROUP(-lgcc -lc -lnosys)
MEMORY { FLASH (rx) : ORIGIN = 0x00035000, LENGTH = 44K
RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 8K
BOOTLOADER_SETTINGS (rw) : ORIGIN = 0x0003FC00, LENGTH = 1K} SECTIONS { /* placing my named section at given address: */ .bootloaderSettings 0x0003FC00 : {
} .uicrBootStartAddress 0x10001014 : {
} /* other placements follow here... / } / .bootloaderSettings (NOLOAD): { *(.bootloaderSettings) } > BOOTLOADER_SETTINGS */ INCLUDE "gcc_nrf51_common.ld"
Is there anything else I'm missing? Thanks
-
Apparently, gcc creates the hex file differently from Keil. The bootloader compiled with gcc writes to the last flash page where the bootloader settings are stored and where the app_valid_setting_apply.hex is writing as well, and that is why the two files conflict. I tried to have the gcc bootloader not write to the last page but some other conflicts come up. I will have to investigate this further next week in order to find a solution that works for gcc.
-
Thanks for the update Stefan. The Manual edit of the merged file did fix my problem. I created a Batch file to merge the images and everything works perfectly. Thank you for the assistance.
-
Locky, I think I may have as similar problem with mergehex
C:\Users\timw\nordic\src\SofM\dfu\bootloader [v6master]> mergehex -m arm_build
bootloader.hex .\bootloader_settings.hex -o bootloadercrc.hex Parsing arm_build\bootloader.hex file. Parsing .\bootloader_settings.hex file. Merging files. ERROR: Merge not possible due to conflict in files.How did you resolve the windows problem you had
- Load Next