Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

DFU with external QSPI memory

Hi,

   I am working on project, in which we using nordic nRF52840 chip. We need to flash the app+SD+BL image file in external QSPI memory.

After prevalidation, the DFU controller starts to send flash image package, we need to receive this and need to save in external QSPI memory. Once the postvalidation is successful, then read all the flash image package stored in external QSPI memory and write it to internal flash memory.

For that we use secure bootloader example code as reference file. I need to know where i need to modify the secure bootloader code.

I noticed that after prevalidation, the flash is erased in on_data_obj_create_request() function in nrf_dfu_req_handler.c file, and flash is written in on_data_obj_write_request() under the same c file. Is that right?

Thanks & Regards

Mohammad Gouse

Parents
  • Hi Hung Bui,

      I have modified the files nrf_fstorage_nvmc.c, nrf_flash.c, nrf_dfu_flash.c (with their corresponding header file) to have external qspi memory interface.

    Once the device enter into DFU mode, it initialize the nrf_dfu_req_handler_init(), so I modified this function by adding nrf_dfu_qspi_init() in it.

      In this project, MX25R6435F used as external QSPI memory. The memory map of this will be same as Nordic system memory map, but without MBR and Bootloader (In our case bootloader in internal flash memory).

    Step 1: After pre-validation, I need to copy the image file (SD + APP) to external QSPI. Now I need to know where I need to change the code to proceed to next step.

Reply
  • Hi Hung Bui,

      I have modified the files nrf_fstorage_nvmc.c, nrf_flash.c, nrf_dfu_flash.c (with their corresponding header file) to have external qspi memory interface.

    Once the device enter into DFU mode, it initialize the nrf_dfu_req_handler_init(), so I modified this function by adding nrf_dfu_qspi_init() in it.

      In this project, MX25R6435F used as external QSPI memory. The memory map of this will be same as Nordic system memory map, but without MBR and Bootloader (In our case bootloader in internal flash memory).

    Step 1: After pre-validation, I need to copy the image file (SD + APP) to external QSPI. Now I need to know where I need to change the code to proceed to next step.

Children
  • Hi Mohammad, 

    I assume you are familiar with the DFU procedure as described here

    After you pass the pre-validation (received the init packet and then got the NRF_DFU_OP_OBJECT_WRITE to execute it), you will receive the data objects. 

    They will be handled inside nrf_dfu_data_req(). It will start with the NRF_DFU_OP_OBJECT_CREATE and the page will be erased with the call to nrf_dfu_flash_erase() inside on_data_obj_create_request(). You would need to modify that function to erase the QSPI flash page instead. 

    Next is NRF_DFU_OP_OBJECT_WRITE , which handled in on_data_obj_write_request(). You need to modify nrf_dfu_flash_store() to store on QSPI. And so on. 

    I'm not 100% sure why you would need to make the addressing on QSPI the same as on the internal chip. But it's up to you. You can have a look at our discussion with TomWS above to know about other stuff you need to modify. 

  • Hi Hung Bui,

      Thanks for your response.

    I have modified nrf_dfu_flash_erase to qspi_earse in on_data_obj_create_request() and nrf_dfu_flash_store to QSPI store in on_data_obj_write_request().

    Its that enough for storing the firmware to QSPI memory?

    The addressing is same as internal chip, so i assume that i don't need to change nrf_dfu_bank0_start_addr, nrf_dfu_bank1_start_addr, nrf_dfu_app_start_address and nrf_dfu_softdevice_start_address. And also the nrf_dfu_cache_prepare().

    Is that correct?

    If yes, then i will proceed to post validation process.

  • Hi Mohammad, 

    Unfortunately, I haven't tried to change the storage from internally to QSPI before, so I don't know for sure if that all you need. 

    Before you go to the next step, please verify that you can store the image on QSPI flash and it stored properly. 

    One advantage of having external flash is that you can store all 3 image (SD+BL+APP) at once compare to the traditional DFU to do that we need to do it in 2 tries (first SD+BL, after that APP). To utilize this, you need to modify the bootloader to take all 3 images and update the app after BL updated. 

  • Hi Hung,

    While i am testing secure bootloader with external QSPI, i am getting the following error,

    C:\vault>nrfutil dfu usb-serial -pkg app_dfu_pkg.zip -p COM5 -b 115200
    [###################################-] 98% 00:00:01
    Traceback (most recent call last):
    File "C:\Python27\Scripts\nrfutil-script.py", line 11, in <module>
    load_entry_point('nrfutil==5.2.0', 'console_scripts', 'nrfutil')()
    File "c:\python27\lib\site-packages\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
    File "c:\python27\lib\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
    File "c:\python27\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "c:\python27\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "c:\python27\lib\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "c:\python27\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
    File "c:\python27\lib\site-packages\nordicsemi\__main__.py", line 1001, in usb_serial
    timeout)
    File "c:\python27\lib\site-packages\nordicsemi\__main__.py", line 956, in do_serial
    dfu.dfu_send_images()
    File "c:\python27\lib\site-packages\nordicsemi\dfu\dfu.py", line 117, in dfu_send_images
    self._dfu_send_image(self.manifest.softdevice_bootloader)
    File "c:\python27\lib\site-packages\nordicsemi\dfu\dfu.py", line 102, in _dfu_send_image
    self.dfu_transport.send_firmware(data)
    File "c:\python27\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 302, in send_firmware
    self.__execute()
    File "c:\python27\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 421, in __execute
    self.__get_response(DfuTransportSerial.OP_CODE['Execute'])
    File "c:\python27\lib\site-packages\nordicsemi\dfu\dfu_transport_serial.py", line 502, in __get_response
    raise NordicSemiException('Extended Error 0x{:02X}: {}'.format(resp[3], data))
    pc_ble_driver_py.exceptions.NordicSemiException: Extended Error 0x0C: The hash of the received firmware image does not match the hash in the init packet.

    Pls help me to solve this issue

  • Hi Mohammad, 

    The error suggests that after the image is received on the nRF52 side, the calculation (post validation) of the image received showing that the hash of the packet doesn't match with the hash in the init packet. 

    You would need to check if : 

    - The image you received and stored properly (read the flash out and compare it with the original image) 

    - Check if the calculation in post validation postvalidate_app() is correct

    - Check if the hash received in the init packet is parse correctly. 

Related