This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UNABLE TO GENERATE PRIVATE KEY

Hi,

I am following a tutorial in order to learn the procedure for DFU OTA . I installed the nrfutil but still unable to generate the private key.

I have tried several commands like :

nrfutil.exe keys generate private.key

nrfutil.exe keys generate priv.pem

but it did not work

I think i am using the latest version . 5.0.0

I am getting such errors : TypeError: write() argument must be str, not bytes
NameError: name 'raw_input' is not defined

Please suggest.
Could I be in wrong directory while writing these commands ?
C:\Users\ArshdeepMalik>nrfutil.exe keys generate private.key

Thanks much!

  • How do I build the bootloader using the private key? it should be the public key right ??

    As I told you, I did try this procedure once but now every time I flash (with normal SES IDE using a USB cable, not even with dfu) any program from ble_peripheral example, I end up in a DFU mode Though it works fine if I flash any program from peripheral example.

    see in the attached pictures, I flashed ble_app_bms example but the board is advertising as DfuTarg

  • Also can you please tell the steps to erase the memory using command line tools (nrfprog -e) . Have never used command line tool. or is there any other way to do so ? if knew how to do it using nrfGo studio but now that does not work . 

    Thanks, 

  • Hi.

    Sorry for the confusion, I will try to make things a bit clearer.

    nrfjprog is a part of the nRF5x Command Line Tools and you can find a user guide here. The installation is described here. And a command reference list is described here.  When you have installed the Command Line Tools, you can open a cmd window and type "nrfjprog.exe -e". This will erase available code and UICR flash areas and reset the device, like this:

    The bootloader question:

    Can we start from scratch, where you follow this procedure:

    Step 1.

    Generate a private key by running this command in cmd in your SDK 15 folder:

    nrfutil keys generate priv.pem

    Step 2.

    Generate a public key file from that private key by running this command in cmd in your SDK 15 folder:

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

    You should now have a file named dfu_public_key.c in your SDK 15 folder.

    Step 3.

    Open the folder nRF5_SDK_15.0.0_a53641a\examples\dfu

    You see that there is a file named dfu_public_key.c, delete this file.

    Take the file you generated in step 2 and move it to this folder.

    Step 4.

    Open up the SES project in the folder nRF5_SDK_15.0.0_a53641a\examples\dfu\secure_bootloader\pca10056_ble\ses and build it.

    After you have built it the folders: \Output\Release\Exe will appear in the folder structure. Open these folders and copy the file named secure_bootloader_ble_s140_pca10056.hex to your SDK 15 folder. This is the .hex file for the secure bootloader you have created.

    Step 5.

    Open the folder nRF5_SDK_15.0.0_a53641a\components\softdevice\s140\hex, and copy the .hex file s140_nrf52_6.0.0_softdevice.hex to your SDK 15 folder.

    Step 6.

    Create an application, for example the ble_app_bms example, and copy the .hex file as you did for the bootloader to your SDK 15 folder (you find the .hex file in nRF5_SDK_15.0.0_a53641a\examples\ble_peripheral\ble_app_bms\pca10056\s140\ses\Output\Release\Exe, named ble_app_bms_pca10056_s140.hex)

    Step 7.

    Generate a bootloader settings page by running this command in cmd in your SDK 15 folder:

    nrfutil settings generate --family NRF52840 --application ble_app_bms_pca10056_s140.hex --application-version 3 --bootloader-version 2 --bl-settings-version 1 settings.hex

    The output looks like this:

    Step 8.

    Merge the settings.hex and secure_bootloader_ble_s140_pca10056.hex together by running this command in cmd in your SDK 15 folder:

    mergehex.exe --merge settings.hex secure_bootloader_ble_s140_pca10056.hex --output my_bootloader.hex

    The output looks like this:

    Step 9.

    Generate the DFU packet by running this command in cmd in your SDK 15 folder:

    nrfutil pkg generate --hw-version 52 --application-version 3 --application ble_app_bms_pca10056_s140.hex --sd-req 0xA9 --key-file priv.pem app_dfu_package.zip

    The output looks like this:

    Step 10.

    You should now have these files in the SDK 15 folder:

    app_dfu_package.zip

    ble_app_bms_pca10056_s140.hex

    my_bootloader.hex

    priv.pem

    s140_nrf52_6.0.0_softdevice.hex

    secure_bootloader_ble_s140_pca10056.hex

    settings.hex

    Step 11.

    Open the SDK 15 folder in cmd, and write the commands:

    nrfjprog.exe -e

    nrfjprog.exe --program s140_nrf52_6.0.0_softdevice.hex --verify

    nrfjprog.exe --program my_bootloader.hex --verify -r

    The output looks like this:

    You have now programmed the SoftDevice and the Bootloader including the bootloader settings page.

    Step 12.

    Open nRF Connect on your mobile phone and scan:

    When you find DfuTarg click on Connect.

    And click on the DFU button and Select distribution packet (ZIP)

    And select the file app_dfu_package.zip.

    After you have finished the device will reset and start advertising as Nordic_BMS

    Does this make things a bit clearer?

    Best regards,

    Andreas

  • Hi Andreas,

    It did work!!!  You were a great help and support . I am glad to be using a Nordic product.

    I only have one last question, which if you will say I can open a separate ticket for:

    What will be the procedure for our customers to be able to upgrade the firmware using OTA DFU? I see that every time we will have to do a DFU, we need to program the bootloader first . How will our customer using the product will do that ?

    Every time we have a new firmware release, will we have to generate a new set of private and public key ?

    Thanks again Andreas for all the help.

    Regards,

    Arshdeep

  • Hi.

    Sorry for the late reply, I have been away for a few days.

    It depends on what you want to upgrade.

    The reason for programming the bootloader first in the examples, is that we need a bootloader in order to do the DFU. If your Application already has a bootloader, you don't need to program another bootloader.


    The DFU procedure is well documented here, could you take a look at that?

    Best regards,

    Andreas

Related