3 * Denis Peter, MPL AG Switzerland
5 * SPDX-License-Identifier: GPL-2.0+
15 static int scsi_curr_dev; /* current device */
18 * scsi boot command intepreter. Derived from diskboot
20 static int do_scsiboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
22 return common_diskboot(cmdtp, "scsi", argc, argv);
26 * scsi command intepreter
28 static int do_scsi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
37 if (strncmp(argv[1], "res", 3) == 0) {
38 printf("\nReset SCSI\n");
39 #ifndef CONFIG_DM_SCSI
42 ret = scsi_scan(true);
44 return CMD_RET_FAILURE;
47 if (strncmp(argv[1], "inf", 3) == 0) {
48 blk_list_devices(IF_TYPE_SCSI);
51 if (strncmp(argv[1], "dev", 3) == 0) {
52 if (blk_print_device_num(IF_TYPE_SCSI, scsi_curr_dev)) {
53 printf("\nno SCSI devices available\n");
54 return CMD_RET_FAILURE;
59 if (strncmp(argv[1], "scan", 4) == 0) {
60 ret = scsi_scan(true);
62 return CMD_RET_FAILURE;
65 if (strncmp(argv[1], "part", 4) == 0) {
66 if (blk_list_part(IF_TYPE_SCSI))
67 printf("\nno SCSI devices available\n");
72 if (strncmp(argv[1], "dev", 3) == 0) {
73 int dev = (int)simple_strtoul(argv[2], NULL, 10);
75 if (!blk_show_device(IF_TYPE_SCSI, dev)) {
77 printf("... is now current device\n");
79 return CMD_RET_FAILURE;
83 if (strncmp(argv[1], "part", 4) == 0) {
84 int dev = (int)simple_strtoul(argv[2], NULL, 10);
86 if (blk_print_part_devnum(IF_TYPE_SCSI, dev)) {
87 printf("\nSCSI device %d not available\n",
89 return CMD_RET_FAILURE;
96 if (strcmp(argv[1], "read") == 0) {
97 ulong addr = simple_strtoul(argv[2], NULL, 16);
98 ulong blk = simple_strtoul(argv[3], NULL, 16);
99 ulong cnt = simple_strtoul(argv[4], NULL, 16);
102 printf("\nSCSI read: device %d block # %ld, count %ld ... ",
103 scsi_curr_dev, blk, cnt);
104 n = blk_read_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk,
106 printf("%ld blocks read: %s\n", n,
107 n == cnt ? "OK" : "ERROR");
109 } else if (strcmp(argv[1], "write") == 0) {
110 ulong addr = simple_strtoul(argv[2], NULL, 16);
111 ulong blk = simple_strtoul(argv[3], NULL, 16);
112 ulong cnt = simple_strtoul(argv[4], NULL, 16);
115 printf("\nSCSI write: device %d block # %ld, count %ld ... ",
116 scsi_curr_dev, blk, cnt);
117 n = blk_write_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk,
119 printf("%ld blocks written: %s\n", n,
120 n == cnt ? "OK" : "ERROR");
124 return CMD_RET_USAGE;
130 "reset - reset SCSI controller\n"
131 "scsi info - show available SCSI devices\n"
132 "scsi scan - (re-)scan SCSI bus\n"
133 "scsi device [dev] - show or set current device\n"
134 "scsi part [dev] - print partition table of one or all SCSI devices\n"
135 "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
136 " to memory address `addr'\n"
137 "scsi write addr blk# cnt - write `cnt' blocks starting at block\n"
138 " `blk#' from memory address `addr'"
142 scsiboot, 3, 1, do_scsiboot,
143 "boot from SCSI device",