1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2001
4  * Denis Peter, MPL AG Switzerland
5  */
6 
7 /*
8  * SCSI support.
9  */
10 #include <common.h>
11 #include <blk.h>
12 #include <command.h>
13 #include <scsi.h>
14 
15 static int scsi_curr_dev; /* current device */
16 
17 /*
18  * scsi boot command intepreter. Derived from diskboot
19  */
do_scsiboot(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])20 static int do_scsiboot(struct cmd_tbl *cmdtp, int flag, int argc,
21 		       char *const argv[])
22 {
23 	return common_diskboot(cmdtp, "scsi", argc, argv);
24 }
25 
26 /*
27  * scsi command intepreter
28  */
do_scsi(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])29 static int do_scsi(struct cmd_tbl *cmdtp, int flag, int argc,
30 		   char *const argv[])
31 {
32 	int ret;
33 
34 	if (argc == 2) {
35 		if (strncmp(argv[1], "res", 3) == 0) {
36 			printf("\nReset SCSI\n");
37 #ifndef CONFIG_DM_SCSI
38 			scsi_bus_reset(NULL);
39 #endif
40 			ret = scsi_scan(true);
41 			if (ret)
42 				return CMD_RET_FAILURE;
43 			return ret;
44 		}
45 		if (strncmp(argv[1], "scan", 4) == 0) {
46 			ret = scsi_scan(true);
47 			if (ret)
48 				return CMD_RET_FAILURE;
49 			return ret;
50 		}
51 	}
52 
53 	return blk_common_cmd(argc, argv, IF_TYPE_SCSI, &scsi_curr_dev);
54 }
55 
56 U_BOOT_CMD(
57 	scsi, 5, 1, do_scsi,
58 	"SCSI sub-system",
59 	"reset - reset SCSI controller\n"
60 	"scsi info  - show available SCSI devices\n"
61 	"scsi scan  - (re-)scan SCSI bus\n"
62 	"scsi device [dev] - show or set current device\n"
63 	"scsi part [dev] - print partition table of one or all SCSI devices\n"
64 	"scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
65 	"     to memory address `addr'\n"
66 	"scsi write addr blk# cnt - write `cnt' blocks starting at block\n"
67 	"     `blk#' from memory address `addr'"
68 );
69 
70 U_BOOT_CMD(
71 	scsiboot, 3, 1, do_scsiboot,
72 	"boot from SCSI device",
73 	"loadAddr dev:part"
74 );
75