]>
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"); | |
39 | scsi_bus_reset(); | |
c002e39a MS |
40 | ret = scsi_scan(1); |
41 | if (ret) | |
42 | return CMD_RET_FAILURE; | |
43 | return ret; | |
f1d4d937 SG |
44 | } |
45 | if (strncmp(argv[1], "inf", 3) == 0) { | |
11f610ed | 46 | blk_list_devices(IF_TYPE_SCSI); |
f1d4d937 SG |
47 | return 0; |
48 | } | |
49 | if (strncmp(argv[1], "dev", 3) == 0) { | |
11f610ed | 50 | if (blk_print_device_num(IF_TYPE_SCSI, scsi_curr_dev)) { |
f1d4d937 | 51 | printf("\nno SCSI devices available\n"); |
11f610ed | 52 | return CMD_RET_FAILURE; |
e887afc9 | 53 | } |
11f610ed | 54 | |
f1d4d937 SG |
55 | return 0; |
56 | } | |
57 | if (strncmp(argv[1], "scan", 4) == 0) { | |
c002e39a MS |
58 | ret = scsi_scan(1); |
59 | if (ret) | |
60 | return CMD_RET_FAILURE; | |
61 | return ret; | |
f1d4d937 SG |
62 | } |
63 | if (strncmp(argv[1], "part", 4) == 0) { | |
11f610ed | 64 | if (blk_list_part(IF_TYPE_SCSI)) |
f1d4d937 | 65 | printf("\nno SCSI devices available\n"); |
11f610ed | 66 | return 0; |
f1d4d937 SG |
67 | } |
68 | return CMD_RET_USAGE; | |
69 | case 3: | |
70 | if (strncmp(argv[1], "dev", 3) == 0) { | |
71 | int dev = (int)simple_strtoul(argv[2], NULL, 10); | |
11f610ed SG |
72 | |
73 | if (!blk_show_device(IF_TYPE_SCSI, dev)) { | |
74 | scsi_curr_dev = dev; | |
75 | printf("... is now current device\n"); | |
76 | } else { | |
77 | return CMD_RET_FAILURE; | |
73a9cfde | 78 | } |
f1d4d937 SG |
79 | return 0; |
80 | } | |
81 | if (strncmp(argv[1], "part", 4) == 0) { | |
82 | int dev = (int)simple_strtoul(argv[2], NULL, 10); | |
11f610ed SG |
83 | |
84 | if (blk_print_part_devnum(IF_TYPE_SCSI, dev)) { | |
85 | printf("\nSCSI device %d not available\n", | |
86 | dev); | |
87 | return CMD_RET_FAILURE; | |
88 | } | |
89 | return 0; | |
f1d4d937 SG |
90 | } |
91 | return CMD_RET_USAGE; | |
92 | default: | |
93 | /* at least 4 args */ | |
94 | if (strcmp(argv[1], "read") == 0) { | |
95 | ulong addr = simple_strtoul(argv[2], NULL, 16); | |
96 | ulong blk = simple_strtoul(argv[3], NULL, 16); | |
97 | ulong cnt = simple_strtoul(argv[4], NULL, 16); | |
98 | ulong n; | |
11f610ed | 99 | |
f1d4d937 SG |
100 | printf("\nSCSI read: device %d block # %ld, count %ld ... ", |
101 | scsi_curr_dev, blk, cnt); | |
11f610ed SG |
102 | n = blk_read_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk, |
103 | cnt, (ulong *)addr); | |
f1d4d937 SG |
104 | printf("%ld blocks read: %s\n", n, |
105 | n == cnt ? "OK" : "ERROR"); | |
106 | return 0; | |
107 | } else if (strcmp(argv[1], "write") == 0) { | |
108 | ulong addr = simple_strtoul(argv[2], NULL, 16); | |
109 | ulong blk = simple_strtoul(argv[3], NULL, 16); | |
110 | ulong cnt = simple_strtoul(argv[4], NULL, 16); | |
111 | ulong n; | |
11f610ed | 112 | |
f1d4d937 SG |
113 | printf("\nSCSI write: device %d block # %ld, count %ld ... ", |
114 | scsi_curr_dev, blk, cnt); | |
11f610ed SG |
115 | n = blk_write_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk, |
116 | cnt, (ulong *)addr); | |
f1d4d937 SG |
117 | printf("%ld blocks written: %s\n", n, |
118 | n == cnt ? "OK" : "ERROR"); | |
119 | return 0; | |
120 | } | |
73a9cfde SG |
121 | } /* switch */ |
122 | return CMD_RET_USAGE; | |
758c9e69 HTL |
123 | } |
124 | ||
73a9cfde SG |
125 | U_BOOT_CMD( |
126 | scsi, 5, 1, do_scsi, | |
127 | "SCSI sub-system", | |
128 | "reset - reset SCSI controller\n" | |
129 | "scsi info - show available SCSI devices\n" | |
130 | "scsi scan - (re-)scan SCSI bus\n" | |
131 | "scsi device [dev] - show or set current device\n" | |
132 | "scsi part [dev] - print partition table of one or all SCSI devices\n" | |
133 | "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" | |
134 | " to memory address `addr'\n" | |
135 | "scsi write addr blk# cnt - write `cnt' blocks starting at block\n" | |
136 | " `blk#' from memory address `addr'" | |
137 | ); | |
138 | ||
139 | U_BOOT_CMD( | |
140 | scsiboot, 3, 1, do_scsiboot, | |
141 | "boot from SCSI device", | |
142 | "loadAddr dev:part" | |
143 | ); |