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

OTA upgrade example, application upgrade via j-link

I am successfully using the ZigBee OTA upgrade example, but the firmware upgrade takes quite long, approximately a half an hour, so it is not an adequate time at the firmware development stage.
Now my workflow looks like:
1) Test new firmware features without the OTA upgrade cluster;
2) Copying the changes to the main project with the OTA upgrade cluster.
Is there any way to flash the new client firmware (with OTA cluster) just from Segger Embedded Studio using flash_placement.xml? If it is possible, could you please provide the example?

  • Hi.

    I'm looking into this issue.

    Please be patient :-)

    Best regards,

    Andreas

  • Hi again.

    You should be able to rebuild the client, generate a new settings page and flash it with sectorerase:

    make -j -C client\pca10056\blank\armgcc clean
    make -j -C client\pca10056\blank\armgcc 
    
    nrfutil settings generate --family NRF52840 --application client\pca10056\blank\armgcc\_build\nrf52840_xxaa.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 --app-boot-validation VALIDATE_ECDSA_P256_SHA256 --key-file priv.pem settings.hex 
    mergehex -m client\pca10056\blank\armgcc\_build\nrf52840_xxaa.hex settings.hex -o dfu_client.hex 
    
    nrfjprog -f nrf52 -r --program dfu_client.hex --sectorerase
    
    nrfjprog -r

    I've tested it and it worked for me.

    Best regards,

    Andreas

  • Hi.

    Thanks for your reply.

    For the first time, I need to flash MBR, then bootloader, then generate bootloader settings, merge it with client firmware and flash the resulting hex (same commands as you provided).

    But for the second time, I just need to generate the OTA update package by the nrfjprog from my client hex, and use it via OTA server.

    I thought, I don’t need to generate again the bootloader settings because they were already flashed from the first time, so it is possible to download subsequent client firmware from Segger Embedded Studio? However, I can’t find in SES appropriate tuning like the “sectorerase”. I tried to put the path to the bootloader and MBR hex-es in the flash_placement.xml and flash in such a way, but in this case, client firmware was not started at all.

    Could you, please, clarify, if I will generate bootloader settings from the updated client hex (i.e., second and subsequent versions, not the first one), then merge it with client hex and flash by nrfjprog with sectorerase, shall it give me the same result, as if I downloaded the client firmware package via OTA? 

    Does the bootloader settings also changes with each client firmware update, and need to be regenerated each time by nrfjprog? So, it appears as I cannot automate somehow this process via Segger Embedded Studio? 

    Sincerely,

    Anna

  • Hi Anna.

    Sorry for not clarifying enough. My idea of your problem was that you wanted to do a upgrade of your client firmware without having to do OTA, correct?

    About the settings:

    As you can see here, there is many "settings" and each with an purpose. For example, the CRC value (0x67E076C0) is checked by the bootloader when it is booted, if the value is not correct the device will not boot. That is why you have to generate new settings page when you upgrade your device. The settings page also has to be signed with the private key you used to generate the bootloader and the client with.

    Is this more clear?

    How to upload a new firmware without doing it OTA:

    I've used the command line tool nrfutil when I did this test, as I'm not quite sure how SES behaves when it comes to sectorerase. But you can still do this by flashing the output .hex file SES provides.

    1. You generate a private key and the dfu_public_key.c file.

    nrfutil keys generate priv.pem 
    
    nrfutil keys display --key pk --format code priv.pem --out_file dfu_public_key.c 

    2. You generate the 1st edition of your bootloader and client and sign them with your generated key.

    3. You generate and sign a bootloader settings page for the client, you merge this settings page with the client.

    nrfutil settings generate --family NRF52840 --application <path_to_application>.hex --application-version 0x01010101 --bootloader-version 1 --bl-settings-version 2 --app-boot-validation VALIDATE_ECDSA_P256_SHA256 --key-file priv.pem settings.hex 
    mergehex -m <path_to_client>.hex settings.hex -o dfu_client.hex
    

    4. You do the following programming with cmd:

    nrfjprog -f nrf52 -e
    nrfjprog -f nrf52 -r --program <path to mbr_nrf52_2.4.1_mbr>.hex --chiperase
    nrfjprog -f nrf52 -r --program <path to the bootloader hex file>.hex
    nrfjprog -f nrf52 -r --program <path to the merged dfu_client>.hex --sectorerase

    You have now programmed the first edition of your client and bootloader.

    If you now do any modifications to you client, you simply clean the client project, and build it over again.

    If you wish to upgrade your device with your modified client project, you do this:

    1. Clean and rebuild the project.

    2. You generate and sign a bootloader settings page for the modified client, you merge this settings page with the modified client.

    nrfutil settings generate --family NRF52840 --application <path to modified client hex>.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 --app-boot-validation VALIDATE_ECDSA_P256_SHA256 --key-file priv.pem settings.hex 
    mergehex -m <path to modified client hex>.hex settings.hex -o dfu_client.hex 
    

    3. You do the following programming with cmd:

    nrfjprog -f nrf52 -r --program dfu_client.hex --sectorerase 
    
    nrfjprog -r

    And that's it!

     

    AnnaR said:
    Does the bootloader settings also changes with each client firmware update, and need to be regenerated each time by nrfjprog? So, it appears as I cannot automate somehow this process via Segger Embedded Studio? 

     Yes, it does change and you need to regenerate it with nrfutil.

    I hope this clears up a few things.

    Best regards,

    Andreas

  • Hi, Andreas.

    My idea of your problem was that you wanted to do a upgrade of your client firmware without having to do OTA, correct?

    Absolutely correct.

    Many thanks to you for so perfect explanation!

    Sincerely,

    Anna

Related