zephyr: flash HAL requires flash_write_protection_set() calls
In Zephyr there is a flash HAL function: flash_write_protection_set()
which for many SoCs is a stubbed function with no functionality,
but for others performs the unlock / lock procedures required before
writing to flash.
We need to add this function to our flash_area_write() wrapper
to support the hardware that requires it.
This fixes mcuboot flash writing for the nRF5x SoCs.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
diff --git a/boot/zephyr/flash_map.c b/boot/zephyr/flash_map.c
index 2736e94..d4eac7f 100644
--- a/boot/zephyr/flash_map.c
+++ b/boot/zephyr/flash_map.c
@@ -93,9 +93,14 @@
int flash_area_write(const struct flash_area *area, uint32_t off, const void *src,
uint32_t len)
{
+ int rc = 0;
+
SYS_LOG_DBG("%s: area=%d, off=%x, len=%x", __func__,
area->fa_id, off, len);
- return flash_write(boot_flash_device, area->fa_off + off, src, len);
+ flash_write_protection_set(boot_flash_device, false);
+ rc = flash_write(boot_flash_device, area->fa_off + off, src, len);
+ flash_write_protection_set(boot_flash_device, true);
+ return rc;
}
int flash_area_erase(const struct flash_area *area, uint32_t off, uint32_t len)