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

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

  • Hi Hung,

     Inside on_data_obj_write_request(), i am using ret_code_t ret = nrf_drv_qspi_write( p_req->write.p_data,  p_req->write.len, write_addr) to write into QSPI instead of writing into flash. 

    Is that correct?

  • Hi Mohammad, 

    Yes, it's the correct place to replace the nrf_dfu_flash_store() with your qspi function. 

    You then need to check if the image copied to the qspi flash correctly after the image is fully transferred. 

  • Hi Hung,

    <info> nrf_dfu_serial_usb: USB power detected
    <info> nrf_dfu_serial_usb: USB ready
    <warning> nrf_dfu_serial_usb: Could not read from CDC. Error: 0x92.
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_RECEIPT_NOTIF_SET
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_MTU_GET
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_SELECT (command)
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_CREATE (command)
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_WRITE (command)
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_CRC_GET (command)
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_EXECUTE (command)
    <info> nrf_dfu_validation: PB: Init packet data len: 62
    <info> nrf_dfu_validation: Signature required. Checking signature.
    <info> nrf_dfu_validation: Calculating hash (len: 62)
    <info> nrf_dfu_validation: Verify signature
    <info> nrf_dfu_validation: Image verified
    <info> nrf_dfu_validation: Write address set to 0x00001000
    <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    <info> nrf_dfu_req_handler: Writing valid init command to flash.
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_SELECT (data)
    <info> nrf_dfu_req_handler: crc = 0x0, offset = 0x0, max_size = 0x1000
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_CREATE (data)
    <info> nrf_dfu_req_handler: Creating object with size: 1708. Offset: 0x00000000, CRC: 0x00000000
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_WRITE (data)

    ------------------------------------------QSPI write---------------------------------------
    <info> nrf_dfu_req_handler: Wirting to qspi at address 0x1000 with length 0x400
    <info> nrf_dfu_req_handler: Data inconsistent at location = 1023, QSPIData[1023] = 0 and Imagedata[1023] = 32
    <info> nrf_dfu_req_handler: Data inconsistent, times = 1
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_WRITE (data)
    <info> nrf_dfu_req_handler: Wirting to qspi at address 0x1400 with length 0x2AC
    <info> nrf_dfu_req_handler: Data inconsistent at location = 683, QSPIData[683] = 70 and Imagedata[683] = 3
    <info> nrf_dfu_req_handler: Data inconsistent, times = 1

    ------------------------------------------------------------------------------------
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_CRC_GET (data)
    <info> nrf_dfu_req_handler: Offset:1708, CRC:0x4009821F
    <info> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <info> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_EXECUTE (data)
    <info> nrf_dfu_req_handler: Whole firmware image received. Postvalidating.
    <info> nrf_dfu_validation: Hash verification. start address: 0x1000, size: 0x6AC
    <warning> nrf_dfu_validation: Hash verification failed.
    <info> nrf_dfu_validation: Expected FW hash:
    <info> nrf_dfu_validation: 97 AF 3F C4 72 7B DD 8B|..?.r{..
    <info> nrf_dfu_validation: 21 75 95 95 DF 47 D9 88|!u...G..
    <info> nrf_dfu_validation: D1 38 7A C0 32 8C 0C E4|.8z.2...
    <info> nrf_dfu_validation: 0A 11 68 6E 78 7A B3 54|..hnxz.T
    <info> nrf_dfu_validation: Actual FW hash:
    <info> nrf_dfu_validation: 4F 4A FE AE 1A 61 B8 CB|OJ...a..
    <info> nrf_dfu_validation: 96 05 85 07 BA 8B 88 60|.......`
    <info> nrf_dfu_validation: 9E C0 F7 38 11 1D C3 6A|...8...j
    <info> nrf_dfu_validation: BD 04 FC 39 3C 13 BA B6|...9<...
    <warning> nrf_dfu_serial: DFU request completed with result: 0xB
    <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    <info> nrf_dfu_req_handler: All flash operations have completed. DFU completed.
    <info> app: Resetting bootloader.
    <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    <info> app: Inside main
    <info> app: In nrf_bootloader_init
    <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    <info> app: Enter nrf_bootloader_fw_activate
    <info> app: No firmware to activate.
    <info> app: Boot validation failed. No valid app to boot.
    <info> app: DFU mode because app is not valid.
    <info> nrf_bootloader_wdt: WDT is not enabled
    <info> app: in weak nrf_dfu_init_user
    <info> app: Entering DFU mode.
    <info> app: Enter main loop
    <info> nrf_dfu_serial_usb: USB power detected
    <info> nrf_dfu_serial_usb: USB ready

    This is the output from NRF_LOG. The last byte written to QSPI is not same as image received.

  • So you have checked what written in QSPI and the last byte was not the same ? Could you check why that happens ? Note that the size of the last packet is not the same size as other packet. 

Related