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

IoT DFU + Coap -> TFTP Error

[Dev Env]

  • nRF52 DK ( Tech Tour) (PCA10040)

  • IoT SoftDevice (s1xx-iot-prototype3_nrf52_softdevice.hex)

  • IoT SDK 0.9

  • coap server example Base + dfu(tftp) example

[Question] my project coap server + iot dfu + pStorage + twi+adc+....

iot dfu example work well. (examples\iot\tftp\dfu)

but my project (coap server base) + iot dfu example not work.

error is [APPL]:[IOT_TFTP_EVT_ERROR][error:0x0000C848[msg:Unsupported option(s) requested]

how to modify my project header file..

sdk_config.h / pstorage_platform.h...

Parents
  • We found a solution for this while working with the same case in the support portal. I will include a short wrap up here, in case someone else are trying to do the same thing.

    The TFTP application uses pstorage raw mode while handling the DFU firmware file. If you integrate another application which uses regular pstorage, the settings in the pstorage_platform.h file will conflict with the raw mode.

    The DFU firmware file and the settings file is created in iot_dfu_file_create() and iot_dfu_init() respectively (in the iot_dfu.c file). Here you find the macro IOT_FILE_PSTORAGE_RAW_INIT() which creates the new files.

    The bootloader settings file is stored in BOOTLOADER_SETTINGS_ADDRESS (0x0007F000) and have the size of CODE_PAGE_SIZE (0x1000)

    The new firmware file is stored in IOT_DFU_DEFAULT_START_ADDRESS and have the size of BOOTLOADER_REGION_START - IOT_DFU_DEFAULT_START_ADDRESS

    When you change the PSTORAGE_DATA_START_ADDR and PSTORAGE_DATA_END_ADDR (in pstorage_platform.h), which you will normally do when using the regular pstorage to store application data. These settings will conflict with the pstorage raw module used by the TFTP DFU application.

    When using normal pstorage, PSTORAGE_DATA_END_ADDR should be set to below the bootloader (0x0007D000) in order for your application data to not overwrite the bootloader. The problem is that this same variable is checked to be above the bootloader settings file which is stored in the bootloader (at 0x0007F000), this is to check that the settings file doesn't overflow the bootloader. So the check will fail.

    More specific, it is this check in the internal_fopen() function in iot_file_pstorage_raw.c that will fail:

    if((p_file->buffer_size % PSTORAGE_FLASH_PAGE_SIZE != 0) ||
        (start_address + p_file->buffer_size > PSTORAGE_DATA_END_ADDR))
    {
        FILE_ERR("[FILE][PSRaw]: Invalid buffer size. Buffer size: %lu, Page size: %d, Total size: %lu.\r\n",
                 p_file->buffer_size, PSTORAGE_FLASH_PAGE_SIZE, PSTORAGE_DATA_END_ADDR);
        FPSRAW_MUTEX_UNLOCK();
        FILE_TRC("[FILE][PSRaw] << fopen.\r\n");
        return (NRF_ERROR_INVALID_PARAM | IOT_FILE_ERR_BASE);
    }
    

    A solution to this is to create a new PSTORAGE_DATA_END_ADDR variable which is used only by the pstorage raw mode, and set this to 0x00080000, which is where it expects the settings file to end.

    Do you have any feedback on this @ludu?

Reply
  • We found a solution for this while working with the same case in the support portal. I will include a short wrap up here, in case someone else are trying to do the same thing.

    The TFTP application uses pstorage raw mode while handling the DFU firmware file. If you integrate another application which uses regular pstorage, the settings in the pstorage_platform.h file will conflict with the raw mode.

    The DFU firmware file and the settings file is created in iot_dfu_file_create() and iot_dfu_init() respectively (in the iot_dfu.c file). Here you find the macro IOT_FILE_PSTORAGE_RAW_INIT() which creates the new files.

    The bootloader settings file is stored in BOOTLOADER_SETTINGS_ADDRESS (0x0007F000) and have the size of CODE_PAGE_SIZE (0x1000)

    The new firmware file is stored in IOT_DFU_DEFAULT_START_ADDRESS and have the size of BOOTLOADER_REGION_START - IOT_DFU_DEFAULT_START_ADDRESS

    When you change the PSTORAGE_DATA_START_ADDR and PSTORAGE_DATA_END_ADDR (in pstorage_platform.h), which you will normally do when using the regular pstorage to store application data. These settings will conflict with the pstorage raw module used by the TFTP DFU application.

    When using normal pstorage, PSTORAGE_DATA_END_ADDR should be set to below the bootloader (0x0007D000) in order for your application data to not overwrite the bootloader. The problem is that this same variable is checked to be above the bootloader settings file which is stored in the bootloader (at 0x0007F000), this is to check that the settings file doesn't overflow the bootloader. So the check will fail.

    More specific, it is this check in the internal_fopen() function in iot_file_pstorage_raw.c that will fail:

    if((p_file->buffer_size % PSTORAGE_FLASH_PAGE_SIZE != 0) ||
        (start_address + p_file->buffer_size > PSTORAGE_DATA_END_ADDR))
    {
        FILE_ERR("[FILE][PSRaw]: Invalid buffer size. Buffer size: %lu, Page size: %d, Total size: %lu.\r\n",
                 p_file->buffer_size, PSTORAGE_FLASH_PAGE_SIZE, PSTORAGE_DATA_END_ADDR);
        FPSRAW_MUTEX_UNLOCK();
        FILE_TRC("[FILE][PSRaw] << fopen.\r\n");
        return (NRF_ERROR_INVALID_PARAM | IOT_FILE_ERR_BASE);
    }
    

    A solution to this is to create a new PSTORAGE_DATA_END_ADDR variable which is used only by the pstorage raw mode, and set this to 0x00080000, which is where it expects the settings file to end.

    Do you have any feedback on this @ludu?

Children
Related