From 3cb7167e2206fa39d9fc20920727f4b858f0dac6 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Fri, 4 Mar 2022 11:40:12 +0000 Subject: [PATCH] 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 --- firmware/target/mips/ingenic_x1000/nand-x1000.c | 8 ++++---- 1 file 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++; }