When I build and download a WICED4.1 app that supports OTA2, the toolchaining process loads a number of files into the serial flash including the Factory Reset Archive, OTA_APP (snip.ota2_extract), APP0(system image) and a number of other files. The build and download does not put anything in the staging area of the sflash. This causes a bug in the bootloader, because the bootloader always checks the file header of the staging area to see if an extraction was in progress before attempting to load APP0 into RAM. If the staging area indicates an extraction was in progress then the contents of APP0 that I just built and downloaded is ignored and overwritten by extracting whatever out of date old system image is stored in the staging area.
There are several ways to fix this. I chose to remove the WICED_OTA2_IMAGE_EXTRACT_ON_NEXT_BOOT image type and make sure the ota2_dct_config_section.boot_type is always updated to OTA2_BOOT_EXTRACT_UPDATE instead. That way the bootloader only needs to check the boot_type and does not need to read the header of the staging area. This makes the process more like a state machine. Another approach might be to add something to one of the makefiles in the toolchaining process that would invalidate the staging area anytime you did a build and download. My personal preference was to reduce the amount of state information that the bootloader needs to access in order to make the decision about which image should be loaded. There are bound to be other ways to fix this bug please feel free to make suggestions.