@@ -195,7 +195,7 @@ static int np_send_error(uint8_t err_code)
195
195
if (np_comm_cb )
196
196
np_comm_cb -> send ((uint8_t * )& err_status , len );
197
197
198
- return -1 ;
198
+ return 0 ;
199
199
}
200
200
201
201
static int np_send_bad_block_info (uint32_t addr )
@@ -275,16 +275,23 @@ static int _np_cmd_nand_erase(np_prog_t *prog)
275
275
DEBUG_PRINT ("Erase at 0x%lx %lx bytes command\r\n" , addr , len );
276
276
277
277
if (addr & (prog -> chip_info -> block_size - 1 ))
278
- return np_send_error (NP_ERR_ADDR_NOT_ALIGN );
278
+ {
279
+ np_send_error (NP_ERR_ADDR_NOT_ALIGN );
280
+ return -1 ;
281
+ }
279
282
280
283
if (len & (prog -> chip_info -> block_size - 1 ))
281
- return np_send_error (NP_ERR_LEN_NOT_ALIGN );
284
+ {
285
+ np_send_error (NP_ERR_LEN_NOT_ALIGN );
286
+ return -1 ;
287
+ }
282
288
283
289
if (addr + len > prog -> chip_info -> size )
284
290
{
285
291
ERROR_PRINT ("Erase address exceded 0x%lx+0x%lx is more then chip size "
286
292
"0x%lx\r\n" , addr , len , prog -> chip_info -> size );
287
- return np_send_error (NP_ERR_ADDR_EXCEEDED );
293
+ np_send_error (NP_ERR_ADDR_EXCEEDED );
294
+ return -1 ;
288
295
}
289
296
290
297
page = addr / prog -> chip_info -> page_size ;
@@ -293,7 +300,10 @@ static int _np_cmd_nand_erase(np_prog_t *prog)
293
300
while (len )
294
301
{
295
302
if (np_nand_erase (prog , page ))
296
- return np_send_error (NP_ERR_NAND_ERASE );
303
+ {
304
+ np_send_error (NP_ERR_NAND_ERASE );
305
+ return -1 ;
306
+ }
297
307
298
308
if (len >= prog -> chip_info -> block_size )
299
309
len -= prog -> chip_info -> block_size ;
@@ -337,7 +347,8 @@ static int np_cmd_nand_write_start(np_prog_t *prog)
337
347
{
338
348
ERROR_PRINT ("Write address 0x%lx is more then chip size 0x%lx\r\n" ,
339
349
write_start_cmd -> addr , prog -> chip_info -> size );
340
- return np_send_error (NP_ERR_ADDR_EXCEEDED );
350
+ np_send_error (NP_ERR_ADDR_EXCEEDED );
351
+ return -1 ;
341
352
}
342
353
343
354
prog -> addr = write_start_cmd -> addr ;
@@ -418,13 +429,15 @@ static int np_cmd_nand_write_data(np_prog_t *prog)
418
429
NP_PACKET_BUF_SIZE )
419
430
{
420
431
ERROR_PRINT ("Data size is wrong %d\r\n" , write_data_cmd -> len );
421
- return np_send_error (NP_ERR_CMD_DATA_SIZE );
432
+ np_send_error (NP_ERR_CMD_DATA_SIZE );
433
+ return -1 ;
422
434
}
423
435
424
436
if (!prog -> addr_is_valid )
425
437
{
426
438
ERROR_PRINT ("Write address is not set\r\n" );
427
- return np_send_error (NP_ERR_ADDR_INVALID );
439
+ np_send_error (NP_ERR_ADDR_INVALID );
440
+ return -1 ;
428
441
}
429
442
430
443
if (prog -> page .offset + write_data_cmd -> len > prog -> chip_info -> page_size )
@@ -438,7 +451,10 @@ static int np_cmd_nand_write_data(np_prog_t *prog)
438
451
if (prog -> page .offset == prog -> chip_info -> page_size )
439
452
{
440
453
if (np_nand_write (prog , prog -> chip_info ))
441
- return np_send_error (NP_ERR_NAND_WR );
454
+ {
455
+ np_send_error (NP_ERR_NAND_WR );
456
+ return -1 ;
457
+ }
442
458
443
459
prog -> addr += prog -> chip_info -> page_size ;
444
460
if (prog -> addr >= prog -> chip_info -> size )
@@ -476,13 +492,17 @@ static int np_cmd_nand_write_end(np_prog_t *prog)
476
492
if (!prog -> addr_is_valid )
477
493
{
478
494
ERROR_PRINT ("Write address is not set\r\n" );
479
- return np_send_error (NP_ERR_ADDR_INVALID );
495
+ np_send_error (NP_ERR_ADDR_INVALID );
496
+ return -1 ;
480
497
}
481
498
482
499
prog -> addr_is_valid = 0 ;
483
500
484
501
if (np_nand_write (prog , prog -> chip_info ))
485
- return np_send_error (NP_ERR_NAND_WR );
502
+ {
503
+ np_send_error (NP_ERR_NAND_WR );
504
+ return -1 ;
505
+ }
486
506
487
507
Exit :
488
508
return np_send_ok_status ();
@@ -557,7 +577,8 @@ static int _np_cmd_nand_read(np_prog_t *prog)
557
577
{
558
578
ERROR_PRINT ("Read address 0x%lx is more then chip size 0x%lx\r\n" ,
559
579
read_cmd -> addr , prog -> chip_info -> size );
560
- return np_send_error (NP_ERR_ADDR_EXCEEDED );
580
+ np_send_error (NP_ERR_ADDR_EXCEEDED );
581
+ return -1 ;
561
582
}
562
583
563
584
addr = read_cmd -> addr ;
@@ -569,7 +590,10 @@ static int _np_cmd_nand_read(np_prog_t *prog)
569
590
while (read_cmd -> len )
570
591
{
571
592
if (np_nand_read (addr , & page , prog -> chip_info ))
572
- return np_send_error (NP_ERR_NAND_RD );
593
+ {
594
+ np_send_error (NP_ERR_NAND_RD );
595
+ return -1 ;
596
+ }
573
597
574
598
while (page .offset < prog -> chip_info -> page_size && read_cmd -> len )
575
599
{
@@ -603,7 +627,8 @@ static int _np_cmd_nand_read(np_prog_t *prog)
603
627
{
604
628
ERROR_PRINT ("Read address 0x%lx is more then chip size 0x%lx" ,
605
629
addr , prog -> chip_info -> page_size );
606
- return np_send_error (NP_ERR_ADDR_EXCEEDED );
630
+ np_send_error (NP_ERR_ADDR_EXCEEDED );
631
+ return -1 ;
607
632
}
608
633
page .page ++ ;
609
634
page .offset = 0 ;
@@ -640,7 +665,8 @@ static int np_cmd_nand_select(np_prog_t *prog)
640
665
prog -> chip_info = NULL ;
641
666
642
667
ERROR_PRINT ("Chip ID %lu not found\r\n" , select_cmd -> chip_num );
643
- return np_send_error (NP_ERR_CHIP_NOT_FOUND );
668
+ np_send_error (NP_ERR_CHIP_NOT_FOUND );
669
+ return -1 ;
644
670
}
645
671
646
672
return np_send_ok_status ();
@@ -660,13 +686,16 @@ static int np_read_bad_block_info_from_page(np_prog_t *prog, uint32_t block,
660
686
break ;
661
687
case NAND_ERROR :
662
688
ERROR_PRINT ("NAND read bad block info error at 0x%lx\r\n" , addr );
663
- return np_send_error (NP_ERR_NAND_RD );
689
+ np_send_error (NP_ERR_NAND_RD );
690
+ return -1 ;
664
691
case NAND_TIMEOUT_ERROR :
665
692
ERROR_PRINT ("NAND read timeout at 0x%lx\r\n" , addr );
666
- return np_send_error (NP_ERR_NAND_RD );
693
+ np_send_error (NP_ERR_NAND_RD );
694
+ return -1 ;
667
695
default :
668
696
ERROR_PRINT ("Unknown NAND status\r\n" );
669
- return np_send_error (NP_ERR_NAND_RD );
697
+ np_send_error (NP_ERR_NAND_RD );
698
+ return -1 ;
670
699
}
671
700
672
701
if (bad_block_data != NP_NAND_GOOD_BLOCK_MARK )
@@ -746,13 +775,15 @@ static int np_cmd_handler(np_prog_t *prog)
746
775
if (!prog -> chip_info && cmd -> code != NP_CMD_NAND_SELECT )
747
776
{
748
777
ERROR_PRINT ("Chip is not selected\r\n" );
749
- return np_send_error (NP_ERR_CHIP_NOT_SEL );
778
+ np_send_error (NP_ERR_CHIP_NOT_SEL );
779
+ return -1 ;
750
780
}
751
781
752
782
if (!np_cmd_is_valid (cmd -> code ))
753
783
{
754
784
ERROR_PRINT ("Invalid cmd code %d\r\n" , cmd -> code );
755
- return np_send_error (NP_ERR_CMD_INVALID );
785
+ np_send_error (NP_ERR_CMD_INVALID );
786
+ return -1 ;
756
787
}
757
788
758
789
if (cmd_handler [cmd -> code ].exec (prog ))
0 commit comments