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

Secure DFU: Isn't upgrading firmware with custom files

Hello there,

I am working on secure dfu. I followed all the steps mentioned in this post and successfully created the secure .zip file.

Here's what I did(In this order):

  • Loaded Softdevice 6.1.1
  • Flashed "secure_bootloader_ble_s140_pca10056" into DK
  • Used nRF Connect app on my iOS device to upgrade the application.

Here's what is happening:

  • If I use any file from "secure_dfu_test_images", everything is being upgraded correctly. New appication is working as expected.
  • If I use the .hex file from /project/pca10056/blank/ses/Output/Debug/Exe and create a secure .zip file with nrfutil and try to upgrade the application, the upgrade is complete on nRF Connect App. Then LEDs will be off and nothing happens. On restart, nothing boots up - neither BLE nor new App code.
  • If I manually flash the same .hex file using ses -> Target -> Download File -> Intel Hex(After clearing all memory), the application code is working okay. So, it's not Application problem.


It'd be fantastic if you can help me understand what's going on here and tell me how to fox this.

Thanks

Teja

Parents
  • Hi, 

     

    If I use the .hex file from /project/pca10056/blank/ses/Output/Debug/Exe and create a secure .zip file with nrfutil and try to upgrade the application, the upgrade is complete on nRF Connect App. Then LEDs will be off and nothing happens. On restart, nothing boots up - neither BLE nor new App code.

     You should use ble_app_blinky_pca10056_s140.hex under nRF5_SDK\examples\ble_peripheral\ble_app_blinky\hex to create the .zip file to run the BLE application.

    -Amanda H. 

  • I think I get what you're saying.

    I believe, I am not creating "Application" file. Creating the zip files using the .hex file from nRF5_SDK_16.0.0_98a08e2\examples\peripheral\projectName\pca10056\blank\ses\Output\Release\Exe, is not the right way to creating "Application" which bootloader is expecting.

    If my understanding is correct, can you please help me create a right application file to be used in secure USB and/or secure BLE bootloaders?

  • Hi ,

    Here's the process I follow:

    • Get the .hex file from:\SDK\nRF5_SDK_16.0.0_98a08e2\examples\peripheral\xxxxxxxxxxxxt\pca10056\blank\ses\Output\Release\Exe
    • Create a secure package using nrfutil pkg generate --hw-version 52 --application-version 1 --application blinky_mbr.hex --sd-req 0xB6 --key-file private.key blinkyUARTSecure.zip. Please note that I created a custom keys and I did update the bootloader code with the created public key.
    • Send the created package using nrfutil dfu usb-serial -pkg blinkyUARTSecure.zip -p COM4 command. Where COM4 is JLink CDC UART Port

    I tried with blinky_mbr.hex. from nRF5_SDK\examples\dfu\secure_dfu_test_images\uart\nrf52840 However, I got a similar error:

    Traceback (most recent call last):
      File "C:\Users\tejac\AppData\Local\Programs\Python\Python37-32\Scripts\nrfutil-script.py", line 11, in <module>
        load_entry_point('nrfutil==6.0.1', 'console_scripts', 'nrfutil')()
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 829, in __call__
        return self.main(*args, **kwargs)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 782, in main
        rv = self.invoke(ctx)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1259, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1259, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1066, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 610, in invoke
        return callback(*args, **kwargs)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\__main__.py", line 994, in usb_serial
        timeout)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\__main__.py", line 949, in do_serial
        dfu.dfu_send_images()
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu.py", line 127, in dfu_send_images
        self._dfu_send_image(self.manifest.application)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu.py", line 95, in _dfu_send_image
        self.dfu_transport.send_init_packet(data)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 255, in send_init_packet
        self.__stream_data(data=init_packet)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 474, in __stream_data
        response = self.__calculate_checksum()
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 409, in __calculate_checksum
        response = self.__get_response(DfuTransportSerial.OP_CODE['CalcChecSum'])
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 492, in __get_response
        + 'Expected: 0x{:02X} Received: 0x{:02X}'.format(operation, resp[1]))
    pc_ble_driver_py.exceptions.NordicSemiException: Unexpected Executed OP_CODE.
    Expected: 0x03 Received: 0xCD

  • Hi Teja, 

     

    tejaChintalapati said:
    Create a secure package using nrfutil pkg generate --hw-version 52 --application-version 1 --application blinky_mbr.hex --sd-req 0xB6 --key-file private.key blinkyUARTSecure.zip. Please note that I created a custom keys and I did update the bootloader code with the created public key.

     You should use

    nrfutil pkg generate --hw-version 52 --application-version 1 --application blinky_mbr.hex --sd-req 0x00 --key-file private.key blinkyUARTSecure.zip

    An empty sd_req list is equivalent to an sd_req list containing a single 0x00. Please see Updates without a SoftDevice.

    -Amanda H. 

  • Hi Amanda,

    Thank you for responding to this. I really appreciate your help during the pandemic like this.

    I did try with nrfutil pkg generate --hw-version 52 --application-version 1 --application blinky_mbr.hex --sd-req 0x00 --key-file private.key blinkyUARTSecure.zip.e

    With the firmware I have, I got this error:

    nrfutil pkg generate --hw-version 52 --application-version 1 --application Firmware_PD52840V1R1_ParkAssist.hex --sd-req 0x00 --key-file private.key PDFW.zip
    Zip created at PDFW.zip
    
    C:\Users\tejac>nrfutil dfu usb-serial -pkg PDFW.zip -p COM4
    
    Traceback (most recent call last):
      File "C:\Users\tejac\AppData\Local\Programs\Python\Python37-32\Scripts\nrfutil-script.py", line 11, in <module>
        load_entry_point('nrfutil==6.0.1', 'console_scripts', 'nrfutil')()
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 829, in __call__
        return self.main(*args, **kwargs)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 782, in main
        rv = self.invoke(ctx)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1259, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1259, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1066, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 610, in invoke
        return callback(*args, **kwargs)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\__main__.py", line 994, in usb_serial
        timeout)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\__main__.py", line 949, in do_serial
        dfu.dfu_send_images()
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu.py", line 127, in dfu_send_images
        self._dfu_send_image(self.manifest.application)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu.py", line 95, in _dfu_send_image
        self.dfu_transport.send_init_packet(data)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 255, in send_init_packet
        self.__stream_data(data=init_packet)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 474, in __stream_data
        response = self.__calculate_checksum()
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 409, in __calculate_checksum
        response = self.__get_response(DfuTransportSerial.OP_CODE['CalcChecSum'])
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 492, in __get_response
        + 'Expected: 0x{:02X} Received: 0x{:02X}'.format(operation, resp[1]))
    pc_ble_driver_py.exceptions.NordicSemiException: Unexpected Executed OP_CODE.
    Expected: 0x03 Received: 0x0D

    With Blinky_mdr.hex, I got this error:

    nrfutil pkg generate --hw-version 52 --application-version 1 --application blinky_mbr.hex --sd-req 0x00 --key-file private.key blinkyUARTSecure.zip
    Zip created at blinkyUARTSecure.zip
    
    C:\Users\tejac>nrfutil dfu usb-serial -pkg blinkyUARTSecure.zip -p COM4
    
    Traceback (most recent call last):
      File "C:\Users\tejac\AppData\Local\Programs\Python\Python37-32\Scripts\nrfutil-script.py", line 11, in <module>
        load_entry_point('nrfutil==6.0.1', 'console_scripts', 'nrfutil')()
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 829, in __call__
        return self.main(*args, **kwargs)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 782, in main
        rv = self.invoke(ctx)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1259, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1259, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1066, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 610, in invoke
        return callback(*args, **kwargs)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\__main__.py", line 994, in usb_serial
        timeout)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\__main__.py", line 949, in do_serial
        dfu.dfu_send_images()
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu.py", line 127, in dfu_send_images
        self._dfu_send_image(self.manifest.application)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu.py", line 95, in _dfu_send_image
        self.dfu_transport.send_init_packet(data)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 255, in send_init_packet
        self.__stream_data(data=init_packet)
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 474, in __stream_data
        response = self.__calculate_checksum()
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 409, in __calculate_checksum
        response = self.__get_response(DfuTransportSerial.OP_CODE['CalcChecSum'])
      File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 492, in __get_response
        + 'Expected: 0x{:02X} Received: 0x{:02X}'.format(operation, resp[1]))
    pc_ble_driver_py.exceptions.NordicSemiException: Unexpected Executed OP_CODE.
    Expected: 0x03 Received: 0xF5

    I am not sure what's causing this.

  • Also, I would like to point-out that the Python Version I have is 3.7, as you can see in the log.

    I vaguely remember reading somewhere that nrfutil ONLY works with Python V2.xx

    Do you think that's the issue here?

  • Yes, I think that might be the issue. You could check by typing nrfutil version. You should see the version number if it is supported. Then, you should use the blinky_mbr.zip under RF5_SDK\examples\dfu\secure_dfu_test_images\uart\nrf52840 before you try to create the new package.  

    Please let me know:

    1. Could you see the nrfutil version with nrfutil version?
    2. Does the blinky_mbr.zip (under RF5_SDK\examples\dfu\secure_dfu_test_images\uart\nrf52840) work with unmodified pca10056_uart?

    -Amanda H.

Reply
  • Yes, I think that might be the issue. You could check by typing nrfutil version. You should see the version number if it is supported. Then, you should use the blinky_mbr.zip under RF5_SDK\examples\dfu\secure_dfu_test_images\uart\nrf52840 before you try to create the new package.  

    Please let me know:

    1. Could you see the nrfutil version with nrfutil version?
    2. Does the blinky_mbr.zip (under RF5_SDK\examples\dfu\secure_dfu_test_images\uart\nrf52840) work with unmodified pca10056_uart?

    -Amanda H.

Children
  • Hi Amanda,

    Thank you for the response.

    1. Yes. I can see the version number is 6.0.1
    2. Using the original key, I got the same error:
      Traceback (most recent call last):
        File "C:\Users\tejac\AppData\Local\Programs\Python\Python37-32\Scripts\nrfutil-script.py", line 11, in <module>
          load_entry_point('nrfutil==6.0.1', 'console_scripts', 'nrfutil')()
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 829, in __call__
          return self.main(*args, **kwargs)
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 782, in main
          rv = self.invoke(ctx)
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1259, in invoke
          return _process_result(sub_ctx.command.invoke(sub_ctx))
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1259, in invoke
          return _process_result(sub_ctx.command.invoke(sub_ctx))
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1066, in invoke
          return ctx.invoke(self.callback, **ctx.params)
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 610, in invoke
          return callback(*args, **kwargs)
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\__main__.py", line 994, in usb_serial
          timeout)
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\__main__.py", line 949, in do_serial
          dfu.dfu_send_images()
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu.py", line 127, in dfu_send_images
          self._dfu_send_image(self.manifest.application)
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu.py", line 95, in _dfu_send_image
          self.dfu_transport.send_init_packet(data)
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 255, in send_init_packet
          self.__stream_data(data=init_packet)
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 474, in __stream_data
          response = self.__calculate_checksum()
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 409, in __calculate_checksum
          response = self.__get_response(DfuTransportSerial.OP_CODE['CalcChecSum'])
        File "c:\users\tejac\appdata\local\programs\python\python37-32\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 492, in __get_response
          + 'Expected: 0x{:02X} Received: 0x{:02X}'.format(operation, resp[1]))
      pc_ble_driver_py.exceptions.NordicSemiException: Unexpected Executed OP_CODE.
      Expected: 0x03 Received: 0xF5
  • Hi, 

    This issue seems very similar to this thread. Can you try to disable the mass storage device in the onboard debugger using the MSDDisable in JLink Commander, as described here?

    -Amanda H.

  • Thanks a ton, Amanda. Disabling the Mass Storage helped me solve the problem.

    Now, I could update the firmware using the nRFUtil using default key and created custom key.

    I appreciate your help. Thanks a ton.

Related