@@ -89,22 +89,21 @@ static int wolfBoot_update(int fallback_allowed)
8989 if ((update .fw_size + IMAGE_HEADER_SIZE ) > total_size )
9090 total_size = update .fw_size + IMAGE_HEADER_SIZE ;
9191
92- if (total_size < IMAGE_HEADER_SIZE )
92+ if (total_size <= IMAGE_HEADER_SIZE )
9393 return -1 ;
9494
9595 /* Check the first sector to detect interrupted update */
9696 if ((wolfBoot_get_sector_flag (PART_UPDATE , 0 , & flag ) < 0 ) || (flag == SECT_FLAG_NEW ))
9797 {
98- uint8_t * update_type ;
98+ uint16_t update_type ;
9999 /* In case this is a new update, do the required
100100 * checks on the firmware update
101101 * before starting the swap
102102 */
103103
104- if (wolfBoot_find_header (update .hdr + IMAGE_HEADER_OFFSET , HDR_IMG_TYPE , & update_type ) == sizeof (uint16_t )) {
105- if ((update_type [0 ] != HDR_IMG_TYPE_APP ) || update_type [1 ] != (HDR_IMG_TYPE_AUTH >> 8 ))
106- return -1 ;
107- }
104+ update_type = wolfBoot_get_image_type (PART_UPDATE );
105+ if (((update_type & 0x00FF ) != HDR_IMG_TYPE_APP ) || ((update_type & 0xFF00 ) != HDR_IMG_TYPE_AUTH ))
106+ return -1 ;
108107 if (!update .hdr_ok || (wolfBoot_verify_integrity (& update ) < 0 )
109108 || (wolfBoot_verify_authenticity (& update ) < 0 )) {
110109 return -1 ;
@@ -307,9 +306,7 @@ static void wolfBoot_check_self_update(void)
307306 /* Check for self update in the UPDATE partition */
308307 if ((wolfBoot_get_partition_state (PART_UPDATE , & st ) == 0 ) && (st == IMG_STATE_UPDATING ) &&
309308 (wolfBoot_open_image (& update , PART_UPDATE ) == 0 ) &&
310- (wolfBoot_find_header (update .hdr + IMAGE_HEADER_OFFSET , HDR_IMG_TYPE , & update_type ) == sizeof (uint16_t )) &&
311- update_type [0 ] == HDR_IMG_TYPE_WOLFBOOT &&
312- update_type [1 ] == (HDR_IMG_TYPE_AUTH >> 8 )) {
309+ wolfBoot_get_image_type (PART_UPDATE ) == (HDR_IMG_TYPE_WOLFBOOT | HDR_IMG_TYPE_AUTH )) {
313310 uint32_t update_version = wolfBoot_update_firmware_version ();
314311 if (update_version <= wolfboot_version ) {
315312 hal_flash_unlock ();
0 commit comments