Skip to content

Commit 238e678

Browse files
committed
[SAMA5D3] Fix nand driver read offset
Tested with 6MB image
1 parent 6080cc2 commit 238e678

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

hal/sama5d3.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len)
589589
uint32_t start_page_in_block = mod(page, nand_flash.pages_per_block); /* The start page within this block */
590590
uint32_t in_block_offset = mod(address, nand_flash.block_size); /* The offset of the address within the block */
591591
uint32_t remaining = nand_flash.block_size - in_block_offset; /* How many bytes remaining to read in the first block */
592-
uint32_t len_to_read = len;
592+
int len_to_read = len;
593593
uint8_t *buffer = data;
594594
uint32_t i;
595595
int copy = 0;
@@ -624,6 +624,8 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len)
624624
/* Read (remaining) pages off a block */
625625
for (i = 0; i < pages_to_read; i++) {
626626
nand_read_page(block, start_page_in_block + i, buffer);
627+
if (sz > nand_flash.page_size)
628+
sz = nand_flash.page_size;
627629
len_to_read -= sz;
628630
buffer += sz;
629631
}

0 commit comments

Comments
 (0)