ide.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * (C) Copyright 2000-2011
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * IDE support
  9. */
  10. #include <common.h>
  11. #include <blk.h>
  12. #include <config.h>
  13. #include <watchdog.h>
  14. #include <command.h>
  15. #include <image.h>
  16. #include <asm/byteorder.h>
  17. #include <asm/io.h>
  18. #if defined(CONFIG_IDE_8xx_DIRECT) || defined(CONFIG_IDE_PCMCIA)
  19. # include <pcmcia.h>
  20. #endif
  21. #include <ide.h>
  22. #include <ata.h>
  23. #ifdef CONFIG_STATUS_LED
  24. # include <status_led.h>
  25. #endif
  26. /* Current I/O Device */
  27. static int curr_device = -1;
  28. int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  29. {
  30. int rcode = 0;
  31. switch (argc) {
  32. case 0:
  33. case 1:
  34. return CMD_RET_USAGE;
  35. case 2:
  36. if (strncmp(argv[1], "res", 3) == 0) {
  37. puts("\nReset IDE"
  38. #ifdef CONFIG_IDE_8xx_DIRECT
  39. " on PCMCIA " PCMCIA_SLOT_MSG
  40. #endif
  41. ": ");
  42. ide_init();
  43. return 0;
  44. } else if (strncmp(argv[1], "inf", 3) == 0) {
  45. blk_list_devices(IF_TYPE_IDE);
  46. return 0;
  47. } else if (strncmp(argv[1], "dev", 3) == 0) {
  48. if (blk_print_device_num(IF_TYPE_IDE, curr_device)) {
  49. printf("\nno IDE devices available\n");
  50. return CMD_RET_FAILURE;
  51. }
  52. return 0;
  53. } else if (strncmp(argv[1], "part", 4) == 0) {
  54. if (blk_list_part(IF_TYPE_IDE))
  55. printf("\nno IDE devices available\n");
  56. return 1;
  57. }
  58. return CMD_RET_USAGE;
  59. case 3:
  60. if (strncmp(argv[1], "dev", 3) == 0) {
  61. int dev = (int)simple_strtoul(argv[2], NULL, 10);
  62. if (!blk_show_device(IF_TYPE_IDE, dev)) {
  63. curr_device = dev;
  64. printf("... is now current device\n");
  65. } else {
  66. return CMD_RET_FAILURE;
  67. }
  68. return 0;
  69. } else if (strncmp(argv[1], "part", 4) == 0) {
  70. int dev = (int)simple_strtoul(argv[2], NULL, 10);
  71. if (blk_print_part_devnum(IF_TYPE_IDE, dev)) {
  72. printf("\nIDE device %d not available\n", dev);
  73. return CMD_RET_FAILURE;
  74. }
  75. return 1;
  76. }
  77. return CMD_RET_USAGE;
  78. default:
  79. /* at least 4 args */
  80. if (strcmp(argv[1], "read") == 0) {
  81. ulong addr = simple_strtoul(argv[2], NULL, 16);
  82. ulong cnt = simple_strtoul(argv[4], NULL, 16);
  83. ulong n;
  84. #ifdef CONFIG_SYS_64BIT_LBA
  85. lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
  86. printf("\nIDE read: device %d block # %lld, count %ld...",
  87. curr_device, blk, cnt);
  88. #else
  89. lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
  90. printf("\nIDE read: device %d block # %ld, count %ld...",
  91. curr_device, blk, cnt);
  92. #endif
  93. n = blk_read_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
  94. (ulong *)addr);
  95. printf("%ld blocks read: %s\n",
  96. n, (n == cnt) ? "OK" : "ERROR");
  97. if (n == cnt)
  98. return 0;
  99. else
  100. return 1;
  101. } else if (strcmp(argv[1], "write") == 0) {
  102. ulong addr = simple_strtoul(argv[2], NULL, 16);
  103. ulong cnt = simple_strtoul(argv[4], NULL, 16);
  104. ulong n;
  105. #ifdef CONFIG_SYS_64BIT_LBA
  106. lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
  107. printf("\nIDE write: device %d block # %lld, count %ld...",
  108. curr_device, blk, cnt);
  109. #else
  110. lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
  111. printf("\nIDE write: device %d block # %ld, count %ld...",
  112. curr_device, blk, cnt);
  113. #endif
  114. n = blk_write_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
  115. (ulong *)addr);
  116. printf("%ld blocks written: %s\n", n,
  117. n == cnt ? "OK" : "ERROR");
  118. if (n == cnt)
  119. return 0;
  120. else
  121. return 1;
  122. } else {
  123. return CMD_RET_USAGE;
  124. }
  125. return rcode;
  126. }
  127. }
  128. int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  129. {
  130. return common_diskboot(cmdtp, "ide", argc, argv);
  131. }
  132. U_BOOT_CMD(ide, 5, 1, do_ide,
  133. "IDE sub-system",
  134. "reset - reset IDE controller\n"
  135. "ide info - show available IDE devices\n"
  136. "ide device [dev] - show or set current device\n"
  137. "ide part [dev] - print partition table of one or all IDE devices\n"
  138. "ide read addr blk# cnt\n"
  139. "ide write addr blk# cnt - read/write `cnt'"
  140. " blocks starting at block `blk#'\n"
  141. " to/from memory address `addr'");
  142. U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
  143. "boot from IDE device", "loadAddr dev:part");