@@ -551,44 +551,57 @@ static int np_nand_read(uint32_t addr, np_page_t *page,
551
551
552
552
static int _np_cmd_nand_read (np_prog_t * prog )
553
553
{
554
- uint32_t addr ;
554
+ uint32_t addr , len , write_len ;
555
555
static np_page_t page ;
556
- uint32_t write_len ;
557
556
uint32_t resp_header_size = offsetof(np_resp_t , data );
558
557
uint32_t tx_data_len = sizeof (np_packet_send_buf ) - resp_header_size ;
559
558
np_read_cmd_t * read_cmd = (np_read_cmd_t * )prog -> rx_buf ;
560
559
np_resp_t * resp = (np_resp_t * )np_packet_send_buf ;
561
560
562
- DEBUG_PRINT ("Read at 0x%lx %lx bytes command\r\n" , read_cmd -> addr ,
563
- read_cmd -> len );
561
+ addr = read_cmd -> addr ;
562
+ len = read_cmd -> len ;
563
+ DEBUG_PRINT ("Read at 0x%lx 0x%lx bytes command\r\n" , addr , len );
564
564
565
- if (read_cmd -> addr >= prog -> chip_info -> size )
565
+ if (addr + len >= prog -> chip_info -> size )
566
566
{
567
- ERROR_PRINT ("Read address 0x%lx is more then chip size 0x%lx\r\n" ,
568
- read_cmd -> addr , prog -> chip_info -> size );
567
+ ERROR_PRINT ("Read address 0x%lx+0x%lx is more then chip size 0x%lx\r\n" ,
568
+ addr , len , prog -> chip_info -> size );
569
569
return NP_ERR_ADDR_EXCEEDED ;
570
570
}
571
571
572
- addr = read_cmd -> addr ;
572
+ if (addr & (prog -> chip_info -> page_size - 1 ))
573
+ {
574
+ ERROR_PRINT ("Read address 0x%lx is not aligned to page size 0x%lx\r\n" ,
575
+ addr , prog -> chip_info -> page_size );
576
+ return NP_ERR_ADDR_NOT_ALIGN ;
577
+ }
578
+
579
+ if (len & (prog -> chip_info -> page_size - 1 ))
580
+ {
581
+ ERROR_PRINT ("Read length 0x%lx is not aligned to page size 0x%lx\r\n" ,
582
+ len , prog -> chip_info -> page_size );
583
+ return NP_ERR_LEN_NOT_ALIGN ;
584
+ }
585
+
573
586
page .page = addr / prog -> chip_info -> page_size ;
574
- page .offset = addr % prog -> chip_info -> page_size ;
587
+ page .offset = 0 ;
575
588
576
589
resp -> code = NP_RESP_DATA ;
577
590
578
- while (read_cmd -> len )
591
+ while (len )
579
592
{
580
593
if (np_nand_read (addr , & page , prog -> chip_info ))
581
594
return NP_ERR_NAND_RD ;
582
595
583
- while (page .offset < prog -> chip_info -> page_size && read_cmd -> len )
596
+ while (page .offset < prog -> chip_info -> page_size && len )
584
597
{
585
598
if (prog -> chip_info -> page_size - page .offset >= tx_data_len )
586
599
write_len = tx_data_len ;
587
600
else
588
601
write_len = prog -> chip_info -> page_size - page .offset ;
589
602
590
- if (write_len > read_cmd -> len )
591
- write_len = read_cmd -> len ;
603
+ if (write_len > len )
604
+ write_len = len ;
592
605
593
606
memcpy (resp -> data , page .buf + page .offset , write_len );
594
607
@@ -602,10 +615,10 @@ static int _np_cmd_nand_read(np_prog_t *prog)
602
615
}
603
616
604
617
page .offset += write_len ;
605
- read_cmd -> len -= write_len ;
618
+ len -= write_len ;
606
619
}
607
620
608
- if (read_cmd -> len )
621
+ if (len )
609
622
{
610
623
addr += prog -> chip_info -> page_size ;
611
624
if (addr >= prog -> chip_info -> size )
0 commit comments