x1000: fix bug in nand_read_bytes

This didn't account for partial page reads properly which resulted
in corrupted data. Fortunately, current released bootloaders do not
perform such reads so they don't trigger this bug.

Change-Id: I426a95ef8d0f20f4567498530e216d80e1aceef2
This commit is contained in:
Aidan MacDonald 2022-03-04 11:40:12 +00:00
parent 3bd5f335f7
commit 3cb7167e22

View file

@ -290,14 +290,14 @@ int nand_read_bytes(nand_drv* drv, uint32_t byte_addr, uint32_t byte_len, void*
if(rc < 0)
return rc;
memcpy(buffer, &drv->page_buf[offset], MIN(pg_size, byte_len));
memcpy(buffer, &drv->page_buf[offset], MIN(pg_size - offset, byte_len));
if(byte_len <= pg_size)
if(byte_len <= pg_size - offset)
break;
byte_len -= pg_size - offset;
buffer += pg_size - offset;
offset = 0;
byte_len -= pg_size;
buffer += pg_size;
page++;
}