uint32_t dfu_image_activate (void) { uint32_t err_code = NRF_SUCCESS; dfu_update_status_t update_status; switch (m_dfu_state) { case DFU_STATE_WAIT_4_ACTIVATE: // Stop the DFU Timer because the peer activity need not be monitored any longer. err_code = app_timer_stop(m_dfu_timer_id); APP_ERROR_CHECK(err_code); if (IS_UPDATING_SD()) //lint !e655 suppress Lint Warning 655: Bit-wise operations { update_status.sd_image_size = m_start_packet.sd_image_size; } else { update_status.sd_image_size = NEW_IMAGE_SIZE_EMPTY; } if (IS_UPDATING_BL()) //lint !e655 suppress Lint Warning 655: Bit-wise operations { update_status.bl_image_size = m_start_packet.bl_image_size; } else { update_status.bl_image_size = NEW_IMAGE_SIZE_EMPTY; } if (IS_UPDATING_APP()) //lint !e655 suppress Lint Warning 655: Bit-wise operations { update_status.ap_image_size = m_start_packet.app_image_size; } else { update_status.ap_image_size = NEW_IMAGE_SIZE_EMPTY; } update_status.status_code = DFU_UPDATE_NEW_IMAGES; update_status.bank_used = m_active_bank; update_status.src_image_address = dfu_storage_start_address_get(); bootloader_dfu_update_process(update_status); break; default: err_code = NRF_ERROR_INVALID_STATE; break; } return err_code; }
uint32_t dfu_image_validate() { uint32_t err_code; switch (m_dfu_state) { case DFU_STATE_RX_DATA_PKT: // Check if the application image write has finished. if (m_data_received != m_image_size) { // Image not yet fully transfered by the peer or the peer has attempted to write // too much data. Hence the validation should fail. err_code = NRF_ERROR_INVALID_STATE; } else { m_dfu_state = DFU_STATE_VALIDATE; // Valid peer activity detected. Hence restart the DFU timer. err_code = dfu_timer_restart(); if (err_code == NRF_SUCCESS) { if(IS_UPDATING_BL(m_start_packet)) { m_image_size = m_image_size - ((uint32_t)(&__end_protected_data) - (uint32_t)(&__start_protected_data)); } err_code = dfu_init_postvalidate((uint8_t *)mp_storage_handle_active->block_id, m_image_size); VERIFY_SUCCESS(err_code); m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE; } } break; default: err_code = NRF_ERROR_INVALID_STATE; break; } return err_code; }
uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) { uint32_t err_code; m_start_packet = *(p_packet->params.start_packet); // Check that the requested update procedure is supported. // Currently the following combinations are allowed: // - Application // - SoftDevice // - Bootloader // - SoftDevice with Bootloader if (IS_UPDATING_APP(m_start_packet) && (IS_UPDATING_SD(m_start_packet) || IS_UPDATING_BL(m_start_packet))) { // App update is only supported independently. return NRF_ERROR_NOT_SUPPORTED; } if (!(IS_WORD_SIZED(m_start_packet.sd_image_size) && IS_WORD_SIZED(m_start_packet.bl_image_size) && IS_WORD_SIZED(m_start_packet.app_image_size))) { // Image_sizes are not a multiple of 4 (word size). return NRF_ERROR_NOT_SUPPORTED; } m_image_size = m_start_packet.sd_image_size + m_start_packet.bl_image_size + m_start_packet.app_image_size; if (m_start_packet.bl_image_size > DFU_BL_IMAGE_MAX_SIZE) { return NRF_ERROR_DATA_SIZE; } if (m_image_size > (DFU_IMAGE_MAX_SIZE_FULL)) { return NRF_ERROR_DATA_SIZE; } m_functions.prepare = dfu_prepare_func_app_erase; m_functions.cleared = dfu_cleared_func_app; if (IS_UPDATING_SD(m_start_packet)) { m_functions.activate = dfu_activate_sd; } else if (IS_UPDATING_BL(m_start_packet)) { m_functions.activate = dfu_activate_bl; } else { m_functions.activate = dfu_activate_app; } switch (m_dfu_state) { case DFU_STATE_IDLE: // Valid peer activity detected. Hence restart the DFU timer. err_code = dfu_timer_restart(); if (err_code != NRF_SUCCESS) { return err_code; } m_functions.prepare(m_image_size); break; default: err_code = NRF_ERROR_INVALID_STATE; break; } return err_code; }
uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) { uint32_t err_code = NRF_SUCCESS; m_start_packet = p_packet->params.start_packet; // Check that the requested update procedure is supported. // Currently the following combinations are allowed: // - Application // - SoftDevice // - Bootloader // - SoftDevice with Bootloader if (IS_UPDATING_APP() && //lint !e655 suppress lint warning 655: bit-wise operations (IS_UPDATING_SD() || //lint !e655 suppress Lint Warning 655: Bit-wise operations IS_UPDATING_BL() || //lint !e655 suppress lint warning 655: bit-wise operations ((m_start_packet.app_image_size & (sizeof(uint32_t) - 1)) != 0))) { // Image_size is not a multiple of 4 (word size). return NRF_ERROR_NOT_SUPPORTED; } if (IS_UPDATING_SD() && //lint !e655 suppress lint warning 655: bit-wise operations ((m_start_packet.sd_image_size & (sizeof(uint32_t) - 1)) != 0)) { // Image_size is not a multiple of 4 (word size). return NRF_ERROR_NOT_SUPPORTED; } if (IS_UPDATING_BL() && //lint !e655 suppress lint warning 655: bit-wise operations ((m_start_packet.bl_image_size & (sizeof(uint32_t) - 1)) != 0)) { // Image_size is not a multiple of 4 (word size). return NRF_ERROR_NOT_SUPPORTED; } m_image_size = m_start_packet.sd_image_size + m_start_packet.bl_image_size + m_start_packet.app_image_size + m_start_packet.info_bytes_size; if (IS_UPDATING_BL() && m_start_packet.bl_image_size > DFU_BL_IMAGE_MAX_SIZE)//lint !e655 suppress Lint Warning 655: Bit-wise operations { return NRF_ERROR_DATA_SIZE; } else if (m_image_size > DFU_IMAGE_MAX_SIZE_FULL) { return NRF_ERROR_DATA_SIZE; } else { // Do nothing. } // If new softdevice size is greater than the code region 1 boundary if (IS_UPDATING_SD() && m_start_packet.sd_image_size > (CODE_REGION_1_START - SOFTDEVICE_REGION_START))//lint !e655 suppress Lint Warning 655: Bit-wise operations { //calculate storage starting offset. uint32_t storage_starting_offset; storage_starting_offset = m_start_packet.sd_image_size - (CODE_REGION_1_START - SOFTDEVICE_REGION_START); storage_starting_offset = CODE_REGION_1_START + storage_starting_offset; if (storage_starting_offset & ~(NRF_FICR->CODEPAGESIZE - 1)) { storage_starting_offset &= ~(NRF_FICR->CODEPAGESIZE - 1); storage_starting_offset += NRF_FICR->CODEPAGESIZE; } m_storage_handle_app.block_id = storage_starting_offset; } switch (m_dfu_state) { case DFU_STATE_RX_INIT_PKT: // Valid peer activity detected. Hence restart the DFU timer. err_code = dfu_timer_restart(); if (err_code != NRF_SUCCESS) { return err_code; } m_dfu_state = DFU_STATE_RDY; //break; fallthrough case DFU_STATE_RDY: break; default: err_code = NRF_ERROR_INVALID_STATE; break; } return err_code; }