ide.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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_PCMCIA)
  19. # include <pcmcia.h>
  20. #endif
  21. #include <ide.h>
  22. #include <ata.h>
  23. #ifdef CONFIG_LED_STATUS
  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. ide_init();
  39. return 0;
  40. } else if (strncmp(argv[1], "inf", 3) == 0) {
  41. blk_list_devices(IF_TYPE_IDE);
  42. return 0;
  43. } else if (strncmp(argv[1], "dev", 3) == 0) {
  44. if (blk_print_device_num(IF_TYPE_IDE, curr_device)) {
  45. printf("\nno IDE devices available\n");
  46. return CMD_RET_FAILURE;
  47. }
  48. return 0;
  49. } else if (strncmp(argv[1], "part", 4) == 0) {
  50. if (blk_list_part(IF_TYPE_IDE))
  51. printf("\nno IDE devices available\n");
  52. return 1;
  53. }
  54. return CMD_RET_USAGE;
  55. case 3:
  56. if (strncmp(argv[1], "dev", 3) == 0) {
  57. int dev = (int)simple_strtoul(argv[2], NULL, 10);
  58. if (!blk_show_device(IF_TYPE_IDE, dev)) {
  59. curr_device = dev;
  60. printf("... is now current device\n");
  61. } else {
  62. return CMD_RET_FAILURE;
  63. }
  64. return 0;
  65. } else if (strncmp(argv[1], "part", 4) == 0) {
  66. int dev = (int)simple_strtoul(argv[2], NULL, 10);
  67. if (blk_print_part_devnum(IF_TYPE_IDE, dev)) {
  68. printf("\nIDE device %d not available\n", dev);
  69. return CMD_RET_FAILURE;
  70. }
  71. return 1;
  72. }
  73. return CMD_RET_USAGE;
  74. default:
  75. /* at least 4 args */
  76. if (strcmp(argv[1], "read") == 0) {
  77. ulong addr = simple_strtoul(argv[2], NULL, 16);
  78. ulong cnt = simple_strtoul(argv[4], NULL, 16);
  79. ulong n;
  80. #ifdef CONFIG_SYS_64BIT_LBA
  81. lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
  82. printf("\nIDE read: device %d block # %lld, count %ld...",
  83. curr_device, blk, cnt);
  84. #else
  85. lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
  86. printf("\nIDE read: device %d block # %ld, count %ld...",
  87. curr_device, blk, cnt);
  88. #endif
  89. n = blk_read_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
  90. (ulong *)addr);
  91. printf("%ld blocks read: %s\n",
  92. n, (n == cnt) ? "OK" : "ERROR");
  93. if (n == cnt)
  94. return 0;
  95. else
  96. return 1;
  97. } else if (strcmp(argv[1], "write") == 0) {
  98. ulong addr = simple_strtoul(argv[2], NULL, 16);
  99. ulong cnt = simple_strtoul(argv[4], NULL, 16);
  100. ulong n;
  101. #ifdef CONFIG_SYS_64BIT_LBA
  102. lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
  103. printf("\nIDE write: device %d block # %lld, count %ld...",
  104. curr_device, blk, cnt);
  105. #else
  106. lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
  107. printf("\nIDE write: device %d block # %ld, count %ld...",
  108. curr_device, blk, cnt);
  109. #endif
  110. n = blk_write_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
  111. (ulong *)addr);
  112. printf("%ld blocks written: %s\n", n,
  113. n == cnt ? "OK" : "ERROR");
  114. if (n == cnt)
  115. return 0;
  116. else
  117. return 1;
  118. } else {
  119. return CMD_RET_USAGE;
  120. }
  121. return rcode;
  122. }
  123. }
  124. int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  125. {
  126. return common_diskboot(cmdtp, "ide", argc, argv);
  127. }
  128. U_BOOT_CMD(ide, 5, 1, do_ide,
  129. "IDE sub-system",
  130. "reset - reset IDE controller\n"
  131. "ide info - show available IDE devices\n"
  132. "ide device [dev] - show or set current device\n"
  133. "ide part [dev] - print partition table of one or all IDE devices\n"
  134. "ide read addr blk# cnt\n"
  135. "ide write addr blk# cnt - read/write `cnt'"
  136. " blocks starting at block `blk#'\n"
  137. " to/from memory address `addr'");
  138. U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
  139. "boot from IDE device", "loadAddr dev:part");