dfu: Fix write block size check on, probably, incorrect device
The write block size has been gathered from device pointed by chosen 'zephyr,flash', while it should be taken from a device a target image flash area resides on. The write block size has been used to check if write buffer is properly aligned. The check is only possible on devices that have write-block-size property in DTS, so in case of SPI connected devices this property may not be available - when device does not have the property, the check is not performed. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
parent
f2a338c77b
commit
323422e8c2
1 changed files with 10 additions and 4 deletions
|
@ -20,21 +20,27 @@
|
||||||
#include <zephyr/devicetree.h>
|
#include <zephyr/devicetree.h>
|
||||||
/* FLASH_AREA_ID() values used below are auto-generated by DT */
|
/* FLASH_AREA_ID() values used below are auto-generated by DT */
|
||||||
#ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE
|
#ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE
|
||||||
#define UPLOAD_FLASH_AREA_ID FLASH_AREA_ID(image_1_nonsecure)
|
#define UPLOAD_FLASH_AREA_LABEL image_1_nonsecure
|
||||||
#else
|
#else
|
||||||
#if FLASH_AREA_LABEL_EXISTS(image_1)
|
#if FLASH_AREA_LABEL_EXISTS(image_1)
|
||||||
#define UPLOAD_FLASH_AREA_ID FLASH_AREA_ID(image_1)
|
#define UPLOAD_FLASH_AREA_LABEL image_1
|
||||||
#else
|
#else
|
||||||
#define UPLOAD_FLASH_AREA_ID FLASH_AREA_ID(image_0)
|
#define UPLOAD_FLASH_AREA_LABEL image_0
|
||||||
#endif
|
#endif
|
||||||
#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE */
|
#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE */
|
||||||
|
|
||||||
|
#define UPLOAD_FLASH_AREA_ID FLASH_AREA_ID(UPLOAD_FLASH_AREA_LABEL)
|
||||||
|
#define UPLOAD_FLASH_AREA_CONTROLLER \
|
||||||
|
DT_GPARENT(DT_NODE_BY_FIXED_PARTITION_LABEL(UPLOAD_FLASH_AREA_LABEL))
|
||||||
|
|
||||||
|
#if DT_NODE_HAS_PROP(UPLOAD_FLASH_AREA_CONTROLLER, write_block_size)
|
||||||
#define FLASH_WRITE_BLOCK_SIZE \
|
#define FLASH_WRITE_BLOCK_SIZE \
|
||||||
DT_PROP(DT_CHOSEN(zephyr_flash), write_block_size)
|
DT_PROP(UPLOAD_FLASH_AREA_CONTROLLER, write_block_size)
|
||||||
|
|
||||||
BUILD_ASSERT((CONFIG_IMG_BLOCK_BUF_SIZE % FLASH_WRITE_BLOCK_SIZE == 0),
|
BUILD_ASSERT((CONFIG_IMG_BLOCK_BUF_SIZE % FLASH_WRITE_BLOCK_SIZE == 0),
|
||||||
"CONFIG_IMG_BLOCK_BUF_SIZE is not a multiple of "
|
"CONFIG_IMG_BLOCK_BUF_SIZE is not a multiple of "
|
||||||
"FLASH_WRITE_BLOCK_SIZE");
|
"FLASH_WRITE_BLOCK_SIZE");
|
||||||
|
#endif
|
||||||
|
|
||||||
int flash_img_buffered_write(struct flash_img_context *ctx, const uint8_t *data,
|
int flash_img_buffered_write(struct flash_img_context *ctx, const uint8_t *data,
|
||||||
size_t len, bool flush)
|
size_t len, bool flush)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue