This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Combining SD, DFU and Application .hex and Programming

Hi guys,

First issue: is that the mergehex.exe fails everytime when trying to Write the merged file. The Error is ERROR: An error occured while writing the file. this has occurred on every attempted combination of SD, DFU and Application.

Second issue: If I try and simply program all three .hex files with nrfjprog.exe I get several warnings. "WARNING: Since the option "--dfu" was not given, the SoftDevice will include UICR settings. Please be aware that Device Firmware Update of the SoftDevice will be possible with these settings." This does not occur if I program the two with nRFgo Studio and I can update the SD just fine.

Third issue: When trying to use nrfjprog.exe the DFU does not detect a valid application. I know this question has been address before, but all references to solutions were based on older code which I don't use. I am using bootloader_util_gcc which is coded differently that bootloader_util_arm. Therefore I don't know how to apply any of the solutions to have the DFU validation the application when programmed.

  • Third Issue: We also tried a lot of things taken from the devzone to get this working. The most promising thing was to patch bootloader_util_arm, but it didn't work properly with one of the later versions. So we were looking for another way of doing this. We think, that the patch to make a application valid shouldn't be in the bootloader code as most given answers suggest. If we only program the bootloader the existing behavior is just fine (enter bootmode automatically). So the patch has to be related to the programming of the chip. We have built a intel-hex file that contains the bootloader settings for a valid application. This hexfile can be merged in the hex-file to be programmed later with nrfjprog.exe.

    NOTE: The file works only if the location of the bootloader settings has not be changed (=> 0x3FC00)

    Hex-File to set valid application in bootloader settings: BootloaderSettingsValidApplication.hex

    First Issue: We are using mergehex.exe without any problem for the same thing as you do. Actually we merge SD, bootloader, application and the hex-file with the bootloader-settings to one hex-file. Can you maybe post the command line of your merge operation?

  • Thanks for the reply, I tried you .hex file, but was not able to merge it with my bootloader .hex file. The error I got was ERROR: Merge not possible due to conflict in files Though it seems like it could be the location of my bootloader, I was sure to set the #define BOOTLOADER_REGION_START 0x0003FC00

    which matches the linkerfile

    BOOTLOADER_SETTINGS (rw) : ORIGIN = 0x0003FC00

    Perhaps someone from Nordic could chime in on a solution?

    For the First Issue: my command line merge code is: mergehex.exe -m s110_nrf51822_7.1.0_softdevice.hex gcc_nrf51_bootloader_xxaa.hex -o output_file.hex

    This was just trying to merge the SoftDevice and my bootloader.

  • 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:

    image description

    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

    SD_BL_APP_valid.hex

    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:

    SD_BL_APP_valid_nRF52832.hex

  • I still seem to get the same error trying to merge your files together. The Error is ERROR: An error occured while writing the file. Could be a windows issue, I'm looking into this.

  • The merge issue was a Windows issue, the OS wasn't giving file write permission to mergehex. Thanks for the help

Related