]>
Commit | Line | Data |
---|---|---|
e887afc9 WD |
1 | /* |
2 | * (C) Copyright 2001 | |
3 | * Denis Peter, MPL AG Switzerland | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
e887afc9 WD |
6 | */ |
7 | ||
8 | /* | |
9 | * SCSI support. | |
10 | */ | |
e887afc9 WD |
11 | #include <common.h> |
12 | #include <command.h> | |
e887afc9 | 13 | #include <scsi.h> |
e887afc9 WD |
14 | |
15 | static int scsi_curr_dev; /* current device */ | |
16 | ||
11f610ed | 17 | /* |
e887afc9 WD |
18 | * scsi boot command intepreter. Derived from diskboot |
19 | */ | |
861fe650 | 20 | static int do_scsiboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
e887afc9 | 21 | { |
7405a133 | 22 | return common_diskboot(cmdtp, "scsi", argc, argv); |
e887afc9 WD |
23 | } |
24 | ||
11f610ed | 25 | /* |
e887afc9 WD |
26 | * scsi command intepreter |
27 | */ | |
861fe650 | 28 | static int do_scsi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
e887afc9 | 29 | { |
c002e39a MS |
30 | int ret; |
31 | ||
e887afc9 | 32 | switch (argc) { |
4c12eeb8 SG |
33 | case 0: |
34 | case 1: | |
35 | return CMD_RET_USAGE; | |
4c12eeb8 | 36 | case 2: |
f1d4d937 SG |
37 | if (strncmp(argv[1], "res", 3) == 0) { |
38 | printf("\nReset SCSI\n"); | |
db13a768 | 39 | #ifndef CONFIG_DM_SCSI |
4682c8a1 | 40 | scsi_bus_reset(NULL); |
db13a768 | 41 | #endif |
8eab1a58 | 42 | ret = scsi_scan(true); |
c002e39a MS |
43 | if (ret) |
44 | return CMD_RET_FAILURE; | |
45 | return ret; | |
f1d4d937 SG |
46 | } |
47 | if (strncmp(argv[1], "inf", 3) == 0) { | |
11f610ed | 48 | blk_list_devices(IF_TYPE_SCSI); |
f1d4d937 SG |
49 | return 0; |
50 | } | |
51 | if (strncmp(argv[1], "dev", 3) == 0) { | |
11f610ed | 52 | if (blk_print_device_num(IF_TYPE_SCSI, scsi_curr_dev)) { |
f1d4d937 | 53 | printf("\nno SCSI devices available\n"); |
11f610ed | 54 | return CMD_RET_FAILURE; |
e887afc9 | 55 | } |
11f610ed | 56 | |
f1d4d937 SG |
57 | return 0; |
58 | } | |
59 | if (strncmp(argv[1], "scan", 4) == 0) { | |
8eab1a58 | 60 | ret = scsi_scan(true); |
c002e39a MS |
61 | if (ret) |
62 | return CMD_RET_FAILURE; | |
63 | return ret; | |
f1d4d937 SG |
64 | } |
65 | if (strncmp(argv[1], "part", 4) == 0) { | |
11f610ed | 66 | if (blk_list_part(IF_TYPE_SCSI)) |
f1d4d937 | 67 | printf("\nno SCSI devices available\n"); |
11f610ed | 68 | return 0; |
f1d4d937 SG |
69 | } |
70 | return CMD_RET_USAGE; | |
71 | case 3: | |
72 | if (strncmp(argv[1], "dev", 3) == 0) { | |
73 | int dev = (int)simple_strtoul(argv[2], NULL, 10); | |
11f610ed SG |
74 | |
75 | if (!blk_show_device(IF_TYPE_SCSI, dev)) { | |
76 | scsi_curr_dev = dev; | |
77 | printf("... is now current device\n"); | |
78 | } else { | |
79 | return CMD_RET_FAILURE; | |
73a9cfde | 80 | } |
f1d4d937 SG |
81 | return 0; |
82 | } | |
83 | if (strncmp(argv[1], "part", 4) == 0) { | |
84 | int dev = (int)simple_strtoul(argv[2], NULL, 10); | |
11f610ed SG |
85 | |
86 | if (blk_print_part_devnum(IF_TYPE_SCSI, dev)) { | |
87 | printf("\nSCSI device %d not available\n", | |
88 | dev); | |
89 | return CMD_RET_FAILURE; | |
90 | } | |
91 | return 0; | |
f1d4d937 SG |
92 | } |
93 | return CMD_RET_USAGE; | |
94 | default: | |
95 | /* at least 4 args */ | |
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); | |
100 | ulong n; | |
11f610ed | 101 | |
f1d4d937 SG |
102 | printf("\nSCSI read: device %d block # %ld, count %ld ... ", |
103 | scsi_curr_dev, blk, cnt); | |
11f610ed SG |
104 | n = blk_read_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk, |
105 | cnt, (ulong *)addr); | |
f1d4d937 SG |
106 | printf("%ld blocks read: %s\n", n, |
107 | n == cnt ? "OK" : "ERROR"); | |
108 | return 0; | |
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); | |
113 | ulong n; | |
11f610ed | 114 | |
f1d4d937 SG |
115 | printf("\nSCSI write: device %d block # %ld, count %ld ... ", |
116 | scsi_curr_dev, blk, cnt); | |
11f610ed SG |
117 | n = blk_write_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk, |
118 | cnt, (ulong *)addr); | |
f1d4d937 SG |
119 | printf("%ld blocks written: %s\n", n, |
120 | n == cnt ? "OK" : "ERROR"); | |
121 | return 0; | |
122 | } | |
73a9cfde SG |
123 | } /* switch */ |
124 | return CMD_RET_USAGE; | |
758c9e69 HTL |
125 | } |
126 | ||
73a9cfde SG |
127 | U_BOOT_CMD( |
128 | scsi, 5, 1, do_scsi, | |
129 | "SCSI sub-system", | |
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'" | |
139 | ); | |
140 | ||
141 | U_BOOT_CMD( | |
142 | scsiboot, 3, 1, do_scsiboot, | |
143 | "boot from SCSI device", | |
144 | "loadAddr dev:part" | |
145 | ); |