diff --git a/Makefile b/Makefile index f3458267..b4c2f23e 100644 --- a/Makefile +++ b/Makefile @@ -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 #------------------------------------------------------------------------------ diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_init.h b/lib/sdk11/components/libraries/bootloader_dfu/dfu_init.h index 8b4807a9..cee408cf 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_init.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_init.h @@ -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__ diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c index f8c90ef8..72aec6b0 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -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; } diff --git a/src/dfu_init.c b/src/dfu_init.c index e19cffa3..adffe9bf 100644 --- a/src/dfu_init.c +++ b/src/dfu_init.c @@ -188,11 +188,11 @@ 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. @@ -200,7 +200,7 @@ uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len) // 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. @@ -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; } diff --git a/src/main.c b/src/main.c index bd997137..05f73985 100644 --- a/src/main.c +++ b/src/main.c @@ -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(); }