aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSukumar Ghorai2010-02-22 15:35:42 -0600
committerChristina Warren2010-02-22 15:35:42 -0600
commit4e4e7ee18f2b73173f187a9188c357ad8f14ec25 (patch)
tree052948f897aa695da9739edb114a54ef9a1c601f
parent78e778e0ea884306841c6499851a1e35177d81d0 (diff)
downloadpsdkla-u-boot-4e4e7ee18f2b73173f187a9188c357ad8f14ec25.tar.gz
psdkla-u-boot-4e4e7ee18f2b73173f187a9188c357ad8f14ec25.tar.xz
psdkla-u-boot-4e4e7ee18f2b73173f187a9188c357ad8f14ec25.zip
MMC read/write commands updated for OMAP3
Example - mmc <read/ write> <slot> <address> <offset> <size> This patch also adds a print message for reads of file sizes > 3MB. Signed-off-by: Sukumar Ghorai <s-ghorai@ti.com>
-rw-r--r--common/cmd_mmc.c38
-rw-r--r--cpu/omap3/mmc.c43
2 files changed, 64 insertions, 17 deletions
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index c37112f03d..d07c027a14 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -95,6 +95,12 @@ int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
95 printf("'%s' is not a number\n", argv[5]); 95 printf("'%s' is not a number\n", argv[5]);
96 goto usage; 96 goto usage;
97 } 97 }
98
99 if (offset%4 != 0) {
100 printf("Offset is not WORD boundary\n");
101 goto usage;
102 }
103
98 /* validate the params */ 104 /* validate the params */
99 if (((dev_num != 0) && (dev_num != 1)) || (size == 0)) 105 if (((dev_num != 0) && (dev_num != 1)) || (size == 0))
100 ret = -1; 106 ret = -1;
@@ -107,31 +113,44 @@ int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
107 113
108 if ((strncmp(argv[1], "write.i", 7) == 0) 114 if ((strncmp(argv[1], "write.i", 7) == 0)
109 && (argv[1][7] == '\0')) { 115 && (argv[1][7] == '\0')) {
116
117 printf("MMC%d Write: offset 0x%08x, size 0x%x\n",
118 dev_num, offset, size);
110 ret = mmc_write_opts(dev_num, 119 ret = mmc_write_opts(dev_num,
111 offset, size, (unsigned char *)addr, &total); 120 offset, size, (unsigned char *)addr, &total);
112 printf("%d bytes written: %s\n", 121 printf("%d bytes written: %s\n",
113 total, ret ? "OK" : "ERROR"); 122 total, ret ? "OK" : "ERROR");
114 } else if ((strncmp(argv[1], "read.i", 6) == 0) && 123 } else if ((strncmp(argv[1], "read.i", 6) == 0) &&
115 (argv[1][6] == '\0')) { 124 (argv[1][6] == '\0')) {
125
126 printf("MMC%d Read: offset 0x%08x, size 0x%x\n",
127 dev_num, offset, size);
116 ret = mmc_read_opts(dev_num, offset, size, 128 ret = mmc_read_opts(dev_num, offset, size,
117 (unsigned char *)addr); 129 (unsigned char *)addr);
118 printf("%d bytes read: %s\n", 130 printf("%d bytes read: %s\n",
119 size, ret ? "OK" : "ERROR"); 131 size, ret ? "OK" : "ERROR");
120 } else if ((strncmp(argv[1], "write", 5) == 0) && 132 } else if ((strncmp(argv[1], "write", 5) == 0) &&
121 (argv[1][5] == '\0')) { 133 (argv[1][5] == '\0')) {
122 ret = mmc_write_block(dev_num, offset, size, 134
135 printf("MMC%d Write: offset 0x%08x, size 0x%x\n",
136 dev_num, offset, size);
137 ret = mmc_write_opts(dev_num, offset, size,
123 (unsigned char *)addr, &total); 138 (unsigned char *)addr, &total);
124 printf("%d sectors written: %s\n", 139 printf("%d bytes written: %s\n",
125 total, ret ? "OK" : "ERROR"); 140 total, ret ? "OK" : "ERROR");
126 } else if ((strncmp(argv[1], "read", 4) == 0) && 141 } else if ((strncmp(argv[1], "read", 4) == 0) &&
127 (argv[1][4] == '\0')) { 142 (argv[1][4] == '\0')) {
128 ret = mmc_read_block(dev_num, offset, size, 143
144 printf("MMC%d Read: offset 0x%08x, size 0x%x\n",
145 dev_num, offset, size);
146 ret = mmc_read_opts(dev_num, offset, size,
129 (unsigned char *)addr); 147 (unsigned char *)addr);
130 printf("Sectors read: %s\n", ret ? "OK" : "ERROR"); 148 printf("%d bytes read: %s\n",
131 } else { 149 size, ret ? "OK" : "ERROR");
150 } else {
132 151
133 goto usage; 152 goto usage;
134 } 153 }
135 /* status of the operation */ 154 /* status of the operation */
136 return ret; 155 return ret;
137 } 156 }
@@ -148,11 +167,10 @@ U_BOOT_CMD(
148 mmc, 6, 1, do_mmc, 167 mmc, 6, 1, do_mmc,
149 "mmc - MMC sub-system\n" 168 "mmc - MMC sub-system\n"
150 "mmc init <dev>\n" 169 "mmc init <dev>\n"
151 "mmc read[.i]/write[.i] <dev> <addr> <block offset> [size]\n", 170 "mmc read[.i]/write[.i] <dev> <addr> <offset> [size]\n",
152 "mmc init - device (0 for MMC1, 1 for MMC2)\n" 171 "mmc init - device (0 for MMC1, 1 for MMC2)\n"
153 "mmc read[.i] device addr offset size - \n" 172 "mmc read[.i]/write[.i] device addr offset size - \n"
154 "mmc write[.i] device addr offset size - \n" 173 "--- write `size' starting at offset `offset' to/from device\n"
155 "--- write `size' starting at offset `offset' to/from eMMC device\n"
156 "device - 0/1 for MMC1/MMC2\n" "`addr' is memory location\n" 174 "device - 0/1 for MMC1/MMC2\n" "`addr' is memory location\n"
157); 175);
158U_BOOT_CMD( 176U_BOOT_CMD(
diff --git a/cpu/omap3/mmc.c b/cpu/omap3/mmc.c
index 9bd78c8296..4dfb231008 100644
--- a/cpu/omap3/mmc.c
+++ b/cpu/omap3/mmc.c
@@ -50,7 +50,8 @@ block_dev_desc_t *mmc_get_dev(int dev)
50 50
51 if ((dev == 0) || (dev == 1)) { 51 if ((dev == 0) || (dev == 1)) {
52 if (cur_card_data[dev].size == 0) 52 if (cur_card_data[dev].size == 0)
53 printf("Card is not Initalized (e.g. mmc init 0)\n"); 53 printf("Card#%d is not Initalized"
54 "(Usage: mmcinit 0/1)\n", dev);
54 else 55 else
55 return &mmc_blk_dev[dev]; 56 return &mmc_blk_dev[dev];
56 } 57 }
@@ -507,9 +508,15 @@ int mmc_read_block(int dev_num, unsigned int blknr,
507 unsigned int num_sec_val = 508 unsigned int num_sec_val =
508 (num_bytes + (MMCSD_SECTOR_SIZE - 1)) / MMCSD_SECTOR_SIZE; 509 (num_bytes + (MMCSD_SECTOR_SIZE - 1)) / MMCSD_SECTOR_SIZE;
509 unsigned int sec_inc_val; 510 unsigned int sec_inc_val;
511 unsigned int percent_complete = 0, percent = 0;
510 512
511 MMC_DPRINT("mmc_read_block Pos=0x%x 0x%x-bytes Add=0x%x\n", 513 MMC_DPRINT("mmc_read_block Pos=0x%x 0x%x-bytes Add=0x%x\n",
512 start_sec, num_bytes, output_buf); 514 start_sec, num_bytes, output_buf);
515 if (cur_card_data[dev_num].size == 0) {
516 printf("Card#%d is not Initalized(e.g mmcinit 0/1)\n", dev_num);
517 return 1;
518 }
519
513 if (num_sec_val == 0) 520 if (num_sec_val == 0)
514 return 1; 521 return 1;
515 522
@@ -523,6 +530,7 @@ int mmc_read_block(int dev_num, unsigned int blknr,
523 MMC_DPRINT("BYTE_MODE\n"); 530 MMC_DPRINT("BYTE_MODE\n");
524 } 531 }
525 532
533 percent = num_sec_val;
526 while (num_sec_val) { 534 while (num_sec_val) {
527 err = mmc_send_cmd(mmc_c->base, MMC_CMD17, argument, resp); 535 err = mmc_send_cmd(mmc_c->base, MMC_CMD17, argument, resp);
528 if (err) 536 if (err)
@@ -535,6 +543,13 @@ int mmc_read_block(int dev_num, unsigned int blknr,
535 output_buf += (MMCSD_SECTOR_SIZE / 4); 543 output_buf += (MMCSD_SECTOR_SIZE / 4);
536 argument += sec_inc_val; 544 argument += sec_inc_val;
537 num_sec_val--; 545 num_sec_val--;
546
547 if ((blkcnt > 0x1800) &&
548 (percent_complete < ((percent - num_sec_val)*100/percent))) {
549 percent_complete = (percent - num_sec_val)*100/percent;
550 printf("\rReading data at 0x%x -- %3d%% complete.",
551 argument, percent_complete);
552 }
538 } 553 }
539 /* FAT file system expects 1 as success */ 554 /* FAT file system expects 1 as success */
540 if (err == 1) 555 if (err == 1)
@@ -543,7 +558,7 @@ int mmc_read_block(int dev_num, unsigned int blknr,
543 return 1; 558 return 1;
544} 559}
545 560
546unsigned char configure_mmc(mmc_card_data *mmc_card_cur) 561unsigned int configure_mmc(mmc_card_data *mmc_card_cur)
547{ 562{
548 int ret_val; 563 int ret_val;
549 unsigned int argument; 564 unsigned int argument;
@@ -650,8 +665,15 @@ int mmc_write_block(int dev_num, unsigned int blknr, unsigned int blkcnt,
650 unsigned int sec_inc_val; 665 unsigned int sec_inc_val;
651 unsigned int num_sec_val = (num_bytes + (MMCSD_SECTOR_SIZE - 1)) / 666 unsigned int num_sec_val = (num_bytes + (MMCSD_SECTOR_SIZE - 1)) /
652 MMCSD_SECTOR_SIZE; 667 MMCSD_SECTOR_SIZE;
668 unsigned int percent_complete = 0, percent = 0;
653 669
654 MMC_DPRINT("+mmc_write_block(0x%x sector)\n", num_sec_val); 670 MMC_DPRINT("+mmc_write_block(0x%x sector)\n", num_sec_val);
671
672 if (cur_card_data[dev_num].size == 0) {
673 printf("Card#%d is not Initalized(e.g mmcinit 0/1)\n", dev_num);
674 return 1;
675 }
676
655 if (blkcnt == 0) 677 if (blkcnt == 0)
656 return 1; 678 return 1;
657 679
@@ -675,6 +697,13 @@ int mmc_write_block(int dev_num, unsigned int blknr, unsigned int blkcnt,
675 output_buf += (MMCSD_SECTOR_SIZE / 4); 697 output_buf += (MMCSD_SECTOR_SIZE / 4);
676 argument += sec_inc_val; 698 argument += sec_inc_val;
677 num_sec_val--; 699 num_sec_val--;
700
701 if ((blkcnt > 0x1800) &&
702 (percent_complete < ((percent - num_sec_val)*100/percent))) {
703 percent_complete = (percent - num_sec_val)*100/percent;
704 printf("\rWriting data at 0x%x -- %3d%% complete.",
705 argument, percent_complete);
706 }
678 } 707 }
679 *total = blkcnt - num_sec_val; 708 *total = blkcnt - num_sec_val;
680 709
@@ -714,7 +743,7 @@ int mmc_init(int slot)
714 (slot == 0) ? IF_TYPE_MMC : IF_TYPE_MMC2; 743 (slot == 0) ? IF_TYPE_MMC : IF_TYPE_MMC2;
715 744
716 mmc_blk_dev[slot].part_type = PART_TYPE_DOS; 745 mmc_blk_dev[slot].part_type = PART_TYPE_DOS;
717 mmc_blk_dev[slot].dev = 0; 746 mmc_blk_dev[slot].dev = slot;
718 mmc_blk_dev[slot].lun = 0; 747 mmc_blk_dev[slot].lun = 0;
719 mmc_blk_dev[slot].type = 0; 748 mmc_blk_dev[slot].type = 0;
720 749
@@ -802,10 +831,10 @@ int mmc_write_opts(int dev_num, unsigned int bytepos, unsigned int bytecnt,
802 unsigned int i, startsec, pos, cursize = 0, blkcnt, tmptotal; 831 unsigned int i, startsec, pos, cursize = 0, blkcnt, tmptotal;
803 unsigned char buf[MMCSD_SECTOR_SIZE]; 832 unsigned char buf[MMCSD_SECTOR_SIZE];
804 833
805 MMC_DPRINT("+mmc_read_opts dev=%d\n", dev_num); 834 MMC_DPRINT("+mmc_write_opts dev=%d\n", dev_num);
806 835
807 /* check, if length is not larger than device */ 836 /* check, if length is not larger than device */
808 MMC_DPRINT("mmc_read_opts Pos=0x%x 0x%x-bytes Add=0x%x\n", 837 MMC_DPRINT("mmc_write_opts Pos=0x%x 0x%x-bytes Add=0x%x\n",
809 bytepos, bytecnt, src); 838 bytepos, bytecnt, src);
810 if (bytecnt == 0) 839 if (bytecnt == 0)
811 return 1; 840 return 1;
@@ -849,9 +878,9 @@ int mmc_write_opts(int dev_num, unsigned int bytepos, unsigned int bytecnt,
849 } 878 }
850 } 879 }
851 880
852 /* check if any fraction to read */ 881 /* check if any fraction to write */
853 if ((err == 0x01) && (bytecnt > 0)) { 882 if ((err == 0x01) && (bytecnt > 0)) {
854 err = mmc_read_block(dev_num, startsec, 1, src); 883 err = mmc_read_block(dev_num, startsec, 1, buf);
855 if (err == 0x01) { 884 if (err == 0x01) {
856 /* make the buffer */ 885 /* make the buffer */
857 for (i = 0; i < bytecnt; i++) 886 for (i = 0; i < bytecnt; i++)