Description
Describe the bug
First of all, this is not nRF Connect fault, it is just possible to reproduce bug using this application. nRF Connect application fails to upgrade when there are two image slots already filled in Zephyr. It just goes back to "connected device tab" very quickly, with no popup.
There is no such problem when using mcumgr
console application. They however differ in commands that they execute within mcumgr SMP protocol. mcumgr
application sends "image erase" first, then continues with "image upload" requests. nRF connect does NOT send "image erase". In theory (based on the mcumgr/smp implementation) sending "image upload" as the first command should work as well, because erase should be done implicitly. In fact mcumgr in Zephyr tries to do that. size
argument passed to flash_erase()
function is the size of image that is going to be uploaded. This fails with -EINVAL, because soc_flash_nrf.c
expects size to be page aligned. So here is the reason why mcumgr
console application succeeds: explicit "image erase" mcumgr/smp command results in erase of the whole slot, which is obviously page aligned.
One possible workaround so far is to enable CONFIG_IMG_ERASE_PROGRESSIVELY=y
, so implicit flash erase operations are done one sector at a time (with proper page alignment).
A clear and concise description of what the bug is.
What have you tried to diagnose or workaround this issue?
To Reproduce
Steps to reproduce the behavior:
- Build firmware with mcuboot and mcumgr support for some nRF MCU (e.g. nrf52840)
- Flash mcuboot and application image, so Zephyr will properly boot
- Upload some application image to second slot using
mcumgr <...> image upload
command (or just make sure there is somethin detected on second slot when doingmcumgr <...> image list
) - Try to do DFU using nRF Connect application (so it will try to overwrite second slot)
- Application should go back to previous screen very fast, i.e. firmware image will not be transfered to Zephyr target
Expected behavior
New application image should be transfered over BT and then booted after waiting some additional time (few seconds).
In the implementation: most likely mcumgr code should "ceil" image size, so flash erase request to flash drivers is sent with page aligned size.
Impact
On a "fresh" target (when there is only one image slot filled) it is only possible to upgrade firmware only once. Any further attempt using nRF Connect application fails.
Screenshots or console output
No logs are printed, because mcumgr implementation is very quiet, when handling errors.
Environment (please complete the following information):
- OS: Android nRF Connect application
- Toolchain: Zephyr SDK
- Commit SHA: 2599f70