summaryrefslogtreecommitdiff
path: root/firmware/drivers/ata_mmc.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/ata_mmc.c')
-rw-r--r--firmware/drivers/ata_mmc.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c
index e27e693528..260418c694 100644
--- a/firmware/drivers/ata_mmc.c
+++ b/firmware/drivers/ata_mmc.c
@@ -476,6 +476,10 @@ static int initialize_card(int card_no)
476 card->r2w_factor = 1 << temp; 476 card->r2w_factor = 1 << temp;
477 card->write_timeout = card->read_timeout * card->r2w_factor; 477 card->write_timeout = card->read_timeout * card->r2w_factor;
478 478
479 /* card size */
480 card->numsectors = mmc_extract_bits(card->csd, 54, 12)
481 * (1 << (mmc_extract_bits(card->csd, 78, 3)+2));
482
479 /* switch to full speed */ 483 /* switch to full speed */
480 setup_sci1(card->bitrate_register); 484 setup_sci1(card->bitrate_register);
481 485
@@ -616,11 +620,10 @@ static int send_single_sector(const unsigned char *buf, int timeout)
616 return ret; 620 return ret;
617} 621}
618 622
619int ata_read_sectors( 623int ata_read_sectors(IF_MV2(int drive,)
620 IF_MV2(int drive,) 624 unsigned long start,
621 unsigned long start, 625 int incount,
622 int incount, 626 void* inbuf)
623 void* inbuf)
624{ 627{
625 int ret = 0; 628 int ret = 0;
626 int i; 629 int i;
@@ -639,6 +642,9 @@ int ata_read_sectors(
639 card = &card_info[current_card]; 642 card = &card_info[current_card];
640 ret = select_card(current_card); 643 ret = select_card(current_card);
641#endif 644#endif
645 if (start + incount > card->numsectors)
646 panicf("Reading past end of card\n");
647
642 if (ret == 0) 648 if (ret == 0)
643 { 649 {
644 if (incount == 1) 650 if (incount == 1)
@@ -702,6 +708,8 @@ int ata_write_sectors(IF_MV2(int drive,)
702 card = &card_info[current_card]; 708 card = &card_info[current_card];
703 ret = select_card(current_card); 709 ret = select_card(current_card);
704#endif 710#endif
711 if (start + count > card->numsectors)
712 panicf("Writing past end of card\n");
705 713
706 if (ret == 0) 714 if (ret == 0)
707 { 715 {