Firmware/src/flash.c
int write_firmware_block(const uint8_t *data, const uint16_t data_len, bool first_block, bool last_block, size_t total_size)
{
    int ret = 0;

    if (total_size > FLASH_BANK_SIZE)
    {
        LOG_ERR("Artifact file size too big (%d)", total_size);
        return -EINVAL;
    }

    if (!data_len)
    {
        LOG_ERR("Data len is zero, nothing to write.");
        return -EINVAL;
    }

    /* Erase bank 1 before starting the write process */
    if (first_block)
    {
        flash_img_init(&dfu_ctx);
        LOG_DBG("Download firmware started, erasing second bank");
        ret = boot_erase_img_bank(FLASH_BANK1_ID);
        if (ret != 0)
        {
            LOG_ERR("Failed to erase flash bank 1: %d", ret);
            return ret;
        }
        LOG_DBG("Finished erasing bank 1");
    }

    return flash_img_buffered_write(&dfu_ctx, (uint8_t *)data, data_len, last_block);
}
// This function is more or less an identical copy to the Foundries.io flash write
// code.
This function is more or less an identical copy to the Foundries.io flash write
code.
This function is more or less an identical copy to the Foundries . io flash write code .
int write_firmware_block(const uint8_t *data, const uint16_t data_len, bool first_block, bool last_block, size_t total_size)
{
    int ret = 0;
    if (total_size > FLASH_BANK_SIZE)
    {
        LOG_ERR("Artifact file size too big (%d)", total_size);
        return -EINVAL;
    }
    if (!data_len)
    {
        LOG_ERR("Data len is zero, nothing to write.");
        return -EINVAL;
    }
    if (first_block)
    {
        flash_img_init(&dfu_ctx);
        LOG_DBG("Download firmware started, erasing second bank");
        ret = boot_erase_img_bank(FLASH_BANK1_ID);
        if (ret != 0)
        {
            LOG_ERR("Failed to erase flash bank 1: %d", ret);
            return ret;
        }
        LOG_DBG("Finished erasing bank 1");
    }
    return flash_img_buffered_write(&dfu_ctx, (uint8_t *)data, data_len, last_block);
}
int write_firmware_block ( const uint8_t * data , const uint16_t data_len , bool first_block , bool last_block , size_t total_size ) { int ret = 0 ; if ( total_size > FLASH_BANK_SIZE ) { LOG_ERR ( " " , total_size ) ; return - EINVAL ; } if ( ! data_len ) { LOG_ERR ( " " ) ; return - EINVAL ; } if ( first_block ) { flash_img_init ( & dfu_ctx ) ; LOG_DBG ( " " ) ; ret = boot_erase_img_bank ( FLASH_BANK1_ID ) ; if ( ret != 0 ) { LOG_ERR ( " " , ret ) ; return ret ; } LOG_DBG ( " " ) ; } return flash_img_buffered_write ( & dfu_ctx , ( uint8_t * ) data , data_len , last_block ) ; }
This function is more or less an identical copy to the Foundries.io flash write
code.
This function is more or less an identical copy to the Foundries . io flash write code .
/* Erase bank 1 before starting the write process */