Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,13 @@ endif
CFLAGS += -DDFU_APP_DATA_RESERVED=$(DFU_APP_DATA_RESERVED)

# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
# Fixes for gcc version 12, 13 and 14.
ifneq (,$(filter 12.% 13.% 14.%,$(shell $(CC) -dumpversion 2>/dev/null)))
# Fixes for gcc version 12, 13, 14 and 15.
ifneq (,$(filter 12.% 13.% 14.% 15.%,$(shell $(CC) -dumpversion 2>/dev/null)))
CFLAGS += --param=min-pagesize=0
# Suppress false-positive -Warray-bounds on memory-mapped address dereferences in SDK headers
CFLAGS += -Wno-array-bounds
# Suppress false-positive -Wunterminated-string-initialization on intentional FAT 8.3 name fields
CFLAGS += -Wno-unterminated-string-initialization
endif

#------------------------------------------------------------------------------
Expand Down
13 changes: 7 additions & 6 deletions lib/sdk11/components/libraries/bootloader_dfu/dfu_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,19 @@ uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len, uin
* - A signature to ensure the image originates from a trusted source.
* Checks are intended to be expanded for customer-specific requirements.
*
* @param[in] p_image Pointer to the received image. The init data provided in the call
* \ref dfu_init_prevalidate will be used for validating the image.
* @param[in] image_len Length of the image data.
* @param[in] p_image Pointer to the received image. The init data provided in the call
* \ref dfu_init_prevalidate will be used for validating the image.
* @param[in] image_len Length of the image data.
* @param[out] p_crc_out Pointer to store the computed CRC of the image. Set on success.
*
* @retval NRF_SUCCESS If the post-validation succeeded, that meant the integrity of the
* image has been verified and the image originates from a trusted
* image has been verified and the image originates from a trusted
* source (signing).
* @retval NRF_ERROR_INVALID_DATA If the post-validation failed, that meant the post check of the
* @retval NRF_ERROR_INVALID_DATA If the post-validation failed, that meant the post check of the
* image failed such as the CRC is not matching the image transfered
* or the verification of the image fails (signing).
*/
uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len);
uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len, uint16_t * p_crc_out);

#endif // DFU_INIT_H__

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ uint32_t dfu_image_validate()
{
m_dfu_state = DFU_STATE_VALIDATE;

err_code = dfu_init_postvalidate((uint8_t *)mp_storage_handle_active->block_id, m_image_size);
err_code = dfu_init_postvalidate((uint8_t *)mp_storage_handle_active->block_id, m_image_size, &m_image_crc);
VERIFY_SUCCESS(err_code);
m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE;
}
Expand Down
7 changes: 4 additions & 3 deletions src/dfu_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,19 @@ uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len, uin
}


uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len)
uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len, uint16_t * p_crc_out)
{
uint16_t image_crc;
uint16_t received_crc;

// In order to support hashing (and signing) then the (decrypted) hash should be fetched and
// the corresponding hash should be calculated over the image at this location.
// If hashing (or signing) is added to the system then the CRC validation should be removed.

// calculate CRC from active block.
image_crc = crc16_compute(p_image, image_len, NULL);

// Decode the received CRC from extended data.
// Decode the received CRC from extended data.
received_crc = uint16_decode((uint8_t *)&m_extended_packet[0]);

// Compare the received and calculated CRC.
Expand All @@ -209,6 +209,7 @@ uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len)
return NRF_ERROR_INVALID_DATA;
}

*p_crc_out = image_crc;
return NRF_SUCCESS;
}

3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ static void check_dfu_mode(void) {

if (_ota_dfu) {
sd_softdevice_disable();
usb_teardown(); // allow booting to app after ota even if usb is connected
usb_teardown();
NVIC_SystemReset(); // clean reset after BLE OTA; GPREGRET is already 0, boots straight to app
} else {
usb_teardown();
}
Expand Down