summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-03-04 11:40:12 +0000
committerAidan MacDonald <amachronic@protonmail.com>2022-03-04 08:57:35 -0500
commit3cb7167e2206fa39d9fc20920727f4b858f0dac6 (patch)
tree91234cde6de07cdeb3629b5b24dd1dd23bba8788
parent3bd5f335f75398382944386cd36cfa3224e991c4 (diff)
downloadrockbox-3cb7167e22.tar.gz
rockbox-3cb7167e22.zip
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
-rw-r--r--firmware/target/mips/ingenic_x1000/nand-x1000.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/firmware/target/mips/ingenic_x1000/nand-x1000.c b/firmware/target/mips/ingenic_x1000/nand-x1000.c
index a818ba10aa..67f1aead45 100644
--- a/firmware/target/mips/ingenic_x1000/nand-x1000.c
+++ b/firmware/target/mips/ingenic_x1000/nand-x1000.c
@@ -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++;
}