Hello!
We are planning to implement OTA update of an application and a second stage bootloader in our product.
As a bootloader chain, we will use NSIB + MCUboot as the nRF Connect SDK documentation suggest.
The SDK provides the FOTA download library, which seems to be capable of downloading images and performing an update of an application or a bootloader.
However, we cannot use the library, because it uses HTTP(S), but we want to use MQTT protocol. So we need to implement the similar functionality by ourselves.
I was learning how the FOTA download library works under the hood. It uses the DFU target library internally in order to write image chunks to the device's flash memory.
But I cannot understand how does the library know in which partition it must put an image?
In case of application only updates, everything seems to be easy - an image must be put into the mcuboot secondary partition.
But in case of an upgradable bootloader there are 3 partitions to chose: mcuboot secondary, s0 and s1.
In the fota_download.c:189 the DFU target initialization function is used with the img_num
argument hardcodded to 0.
So my main question is how does the DFU target library know what it is writing (appication image, or mcuboot s0 image, or mcuboot s1 image)? And how does it know in which partition to write the image?