drivers: flash: nrf_qspi_nor: support read of sub-word lengths

mcuboot and possibly other tools read single byte values to determine
the state of objects.  Rather than fail to do the read of values too
short for this peripheral detect the situation and read into a stack
buffer that meets the length criteria, and on success copy the data
into the provided buffer.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2020-05-13 10:49:59 -05:00 committed by Carles Cufí
commit bfb56c5e20

View file

@ -491,12 +491,19 @@ static inline int qspi_nor_read_id(struct device *dev,
static int qspi_nor_read(struct device *dev, off_t addr, void *dest,
size_t size)
{
void *dptr = dest;
size_t dlen = size;
u8_t buf[4];
if (!dest) {
return -EINVAL;
}
/* read size must be non-zero multiple of 4 bytes */
if (((size % 4U) != 0) || (size == 0)) {
if (size < 4U) {
dest = buf;
size = sizeof(buf);
} else if (((size % 4U) != 0) || (size == 0)) {
return -EINVAL;
}
/* address must be 4-byte aligned */
@ -523,7 +530,13 @@ static int qspi_nor_read(struct device *dev, off_t addr, void *dest,
qspi_wait_for_completion(dev, res);
return qspi_get_zephyr_ret_code(res);
int rc = qspi_get_zephyr_ret_code(res);
if ((rc == 0) && (dest != dptr)) {
memcpy(dptr, dest, dlen);
}
return rc;
}
static int qspi_nor_write(struct device *dev, off_t addr, const void *src,