Skip to content

Commit 20a5494

Browse files
authored
Merge pull request #52 from 7134956/upstream
Firmware: Fixed calculate size for big NAND chips.
2 parents 020a517 + 1fec4e1 commit 20a5494

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

firmware/programmer/nand_programmer.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <inttypes.h>
2020

2121
#define NP_PACKET_BUF_SIZE 64
22-
#define NP_MAX_PAGE_SIZE 0x0840 /* 2KB + 64 spare */
22+
#define NP_MAX_PAGE_SIZE 0x21C0 /* 8KB + 448 spare */
2323
#define NP_WRITE_ACK_BYTES 1984
2424
#define NP_NAND_TIMEOUT 0x1000000
2525

@@ -474,7 +474,7 @@ static int _np_cmd_nand_erase(np_prog_t *prog)
474474
pages = prog->chip_info.total_size / prog->chip_info.page_size;
475475
page_size = prog->chip_info.page_size + prog->chip_info.spare_size;
476476
block_size = pages_in_block * page_size;
477-
total_size = pages * page_size;
477+
total_size = (uint64_t)pages * page_size;
478478
}
479479
else
480480
{
@@ -560,7 +560,7 @@ static int np_cmd_nand_erase(np_prog_t *prog)
560560
return ret;
561561
}
562562

563-
static int np_send_write_ack(uint32_t bytes_ack)
563+
static int np_send_write_ack(uint64_t bytes_ack)
564564
{
565565
np_resp_t resp_header = { NP_RESP_STATUS, NP_STATUS_WRITE_ACK };
566566
np_resp_write_ack_t write_ack = { resp_header, bytes_ack };
@@ -604,7 +604,7 @@ static int np_cmd_nand_write_start(np_prog_t *prog)
604604
prog->page_size = prog->chip_info.page_size +
605605
prog->chip_info.spare_size;
606606
prog->block_size = pages_in_block * prog->page_size;
607-
prog->total_size = pages * prog->page_size;
607+
prog->total_size = (uint64_t)pages * prog->page_size;
608608
}
609609
else
610610
{
@@ -648,6 +648,13 @@ static int np_cmd_nand_write_start(np_prog_t *prog)
648648
return ret;
649649
}
650650

651+
if (prog->page_size > sizeof(prog->page.buf))
652+
{
653+
ERROR_PRINT("Page size 0x%lx"
654+
" is more then buffer size 0x%x\r\n", prog->page_size, sizeof(prog->page.buf));
655+
return NP_ERR_BUF_OVERFLOW;
656+
}
657+
651658
prog->addr = addr;
652659
prog->len = len;
653660
prog->addr_is_set = 1;
@@ -914,7 +921,7 @@ static int _np_cmd_nand_read(np_prog_t *prog)
914921
prog->chip_info.page_size;
915922
page_size = prog->chip_info.page_size + prog->chip_info.spare_size;
916923
block_size = pages_in_block * page_size;
917-
total_size = pages * page_size;
924+
total_size = (uint64_t)pages * page_size;
918925
}
919926
else
920927
{

0 commit comments

Comments
 (0)