boot_serial: Add unaligned stack buffer writing
Fixes a bug when writing to devices which have memory alignment
requirements with data being using directly from a zcbor-response
whereby the alignment of the buffer data does not meet the
requirements of the flash driver.
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
diff --git a/boot/zephyr/Kconfig.serial_recovery b/boot/zephyr/Kconfig.serial_recovery
index 225c430..336b085 100644
--- a/boot/zephyr/Kconfig.serial_recovery
+++ b/boot/zephyr/Kconfig.serial_recovery
@@ -51,6 +51,14 @@
Note that 0 is default upload target when no explicit
selection is done.
+config BOOT_SERIAL_UNALIGNED_BUFFER_SIZE
+ int "Stack buffer for unaligned memory writes"
+ default 64
+ help
+ Specifies the stack usage for a buffer which is used for unaligned
+ memory access when data is written to a device with memory alignment
+ requirements. Set to 0 to disable.
+
config BOOT_MAX_LINE_INPUT_LEN
int "Maximum input line length"
default 512
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
index fbdcddd..1092687 100644
--- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
@@ -245,6 +245,10 @@
#define MCUBOOT_SERIAL_MAX_RECEIVE_SIZE CONFIG_BOOT_SERIAL_MAX_RECEIVE_SIZE
#endif
+#ifdef CONFIG_BOOT_SERIAL_UNALIGNED_BUFFER_SIZE
+#define MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE CONFIG_BOOT_SERIAL_UNALIGNED_BUFFER_SIZE
+#endif
+
/* Support 32-byte aligned flash sizes */
#if DT_HAS_CHOSEN(zephyr_flash)
#if DT_PROP_OR(DT_CHOSEN(zephyr_flash), write_block_size, 0) > 8