From 238e678db62473ccb518cb6daf14f4c801a168e6 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Mon, 30 Sep 2024 15:49:44 +0200 Subject: [PATCH] [SAMA5D3] Fix nand driver read offset Tested with 6MB image --- hal/sama5d3.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hal/sama5d3.c b/hal/sama5d3.c index fe4b581e7..82fffaa7d 100644 --- a/hal/sama5d3.c +++ b/hal/sama5d3.c @@ -589,7 +589,7 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len) uint32_t start_page_in_block = mod(page, nand_flash.pages_per_block); /* The start page within this block */ uint32_t in_block_offset = mod(address, nand_flash.block_size); /* The offset of the address within the block */ uint32_t remaining = nand_flash.block_size - in_block_offset; /* How many bytes remaining to read in the first block */ - uint32_t len_to_read = len; + int len_to_read = len; uint8_t *buffer = data; uint32_t i; int copy = 0; @@ -624,6 +624,8 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len) /* Read (remaining) pages off a block */ for (i = 0; i < pages_to_read; i++) { nand_read_page(block, start_page_in_block + i, buffer); + if (sz > nand_flash.page_size) + sz = nand_flash.page_size; len_to_read -= sz; buffer += sz; }