scsi.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * (C) Copyright 2001
  3. * Denis Peter, MPL AG Switzerland
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * SCSI support.
  9. */
  10. #include <common.h>
  11. #include <command.h>
  12. #include <scsi.h>
  13. static int scsi_curr_dev; /* current device */
  14. /*
  15. * scsi boot command intepreter. Derived from diskboot
  16. */
  17. static int do_scsiboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  18. {
  19. return common_diskboot(cmdtp, "scsi", argc, argv);
  20. }
  21. /*
  22. * scsi command intepreter
  23. */
  24. static int do_scsi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  25. {
  26. int ret;
  27. switch (argc) {
  28. case 0:
  29. case 1:
  30. return CMD_RET_USAGE;
  31. case 2:
  32. if (strncmp(argv[1], "res", 3) == 0) {
  33. printf("\nReset SCSI\n");
  34. scsi_bus_reset();
  35. ret = scsi_scan(1);
  36. if (ret)
  37. return CMD_RET_FAILURE;
  38. return ret;
  39. }
  40. if (strncmp(argv[1], "inf", 3) == 0) {
  41. blk_list_devices(IF_TYPE_SCSI);
  42. return 0;
  43. }
  44. if (strncmp(argv[1], "dev", 3) == 0) {
  45. if (blk_print_device_num(IF_TYPE_SCSI, scsi_curr_dev)) {
  46. printf("\nno SCSI devices available\n");
  47. return CMD_RET_FAILURE;
  48. }
  49. return 0;
  50. }
  51. if (strncmp(argv[1], "scan", 4) == 0) {
  52. ret = scsi_scan(1);
  53. if (ret)
  54. return CMD_RET_FAILURE;
  55. return ret;
  56. }
  57. if (strncmp(argv[1], "part", 4) == 0) {
  58. if (blk_list_part(IF_TYPE_SCSI))
  59. printf("\nno SCSI devices available\n");
  60. return 0;
  61. }
  62. return CMD_RET_USAGE;
  63. case 3:
  64. if (strncmp(argv[1], "dev", 3) == 0) {
  65. int dev = (int)simple_strtoul(argv[2], NULL, 10);
  66. if (!blk_show_device(IF_TYPE_SCSI, dev)) {
  67. scsi_curr_dev = dev;
  68. printf("... is now current device\n");
  69. } else {
  70. return CMD_RET_FAILURE;
  71. }
  72. return 0;
  73. }
  74. if (strncmp(argv[1], "part", 4) == 0) {
  75. int dev = (int)simple_strtoul(argv[2], NULL, 10);
  76. if (blk_print_part_devnum(IF_TYPE_SCSI, dev)) {
  77. printf("\nSCSI device %d not available\n",
  78. dev);
  79. return CMD_RET_FAILURE;
  80. }
  81. return 0;
  82. }
  83. return CMD_RET_USAGE;
  84. default:
  85. /* at least 4 args */
  86. if (strcmp(argv[1], "read") == 0) {
  87. ulong addr = simple_strtoul(argv[2], NULL, 16);
  88. ulong blk = simple_strtoul(argv[3], NULL, 16);
  89. ulong cnt = simple_strtoul(argv[4], NULL, 16);
  90. ulong n;
  91. printf("\nSCSI read: device %d block # %ld, count %ld ... ",
  92. scsi_curr_dev, blk, cnt);
  93. n = blk_read_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk,
  94. cnt, (ulong *)addr);
  95. printf("%ld blocks read: %s\n", n,
  96. n == cnt ? "OK" : "ERROR");
  97. return 0;
  98. } else if (strcmp(argv[1], "write") == 0) {
  99. ulong addr = simple_strtoul(argv[2], NULL, 16);
  100. ulong blk = simple_strtoul(argv[3], NULL, 16);
  101. ulong cnt = simple_strtoul(argv[4], NULL, 16);
  102. ulong n;
  103. printf("\nSCSI write: device %d block # %ld, count %ld ... ",
  104. scsi_curr_dev, blk, cnt);
  105. n = blk_write_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk,
  106. cnt, (ulong *)addr);
  107. printf("%ld blocks written: %s\n", n,
  108. n == cnt ? "OK" : "ERROR");
  109. return 0;
  110. }
  111. } /* switch */
  112. return CMD_RET_USAGE;
  113. }
  114. U_BOOT_CMD(
  115. scsi, 5, 1, do_scsi,
  116. "SCSI sub-system",
  117. "reset - reset SCSI controller\n"
  118. "scsi info - show available SCSI devices\n"
  119. "scsi scan - (re-)scan SCSI bus\n"
  120. "scsi device [dev] - show or set current device\n"
  121. "scsi part [dev] - print partition table of one or all SCSI devices\n"
  122. "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
  123. " to memory address `addr'\n"
  124. "scsi write addr blk# cnt - write `cnt' blocks starting at block\n"
  125. " `blk#' from memory address `addr'"
  126. );
  127. U_BOOT_CMD(
  128. scsiboot, 3, 1, do_scsiboot,
  129. "boot from SCSI device",
  130. "loadAddr dev:part"
  131. );