blob: 387ca1a262ab505c9e680c8874111a91bcf4bc5d [file] [log] [blame]
wdenke887afc2002-08-27 09:44:07 +00001/*
2 * (C) Copyright 2001
3 * Denis Peter, MPL AG Switzerland
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenke887afc2002-08-27 09:44:07 +00006 */
7
8/*
9 * SCSI support.
10 */
wdenke887afc2002-08-27 09:44:07 +000011#include <common.h>
12#include <command.h>
wdenke887afc2002-08-27 09:44:07 +000013#include <scsi.h>
wdenke887afc2002-08-27 09:44:07 +000014
15static int scsi_curr_dev; /* current device */
16
Simon Glassc8e89ab2016-05-01 11:36:09 -060017/*
wdenke887afc2002-08-27 09:44:07 +000018 * scsi boot command intepreter. Derived from diskboot
19 */
Simon Glassc8e89ab2016-05-01 11:36:09 -060020int do_scsiboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
wdenke887afc2002-08-27 09:44:07 +000021{
Rob Herringa20cbf92012-09-21 04:02:30 +000022 return common_diskboot(cmdtp, "scsi", argc, argv);
wdenke887afc2002-08-27 09:44:07 +000023}
24
Simon Glassc8e89ab2016-05-01 11:36:09 -060025/*
wdenke887afc2002-08-27 09:44:07 +000026 * scsi command intepreter
27 */
Simon Glassc8e89ab2016-05-01 11:36:09 -060028int do_scsi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
wdenke887afc2002-08-27 09:44:07 +000029{
30 switch (argc) {
Simon Glassa06dfc72011-12-10 08:44:01 +000031 case 0:
32 case 1:
33 return CMD_RET_USAGE;
Simon Glassa06dfc72011-12-10 08:44:01 +000034 case 2:
Simon Glass5c7bf8e2016-05-01 11:35:58 -060035 if (strncmp(argv[1], "res", 3) == 0) {
36 printf("\nReset SCSI\n");
37 scsi_bus_reset();
38 scsi_scan(1);
39 return 0;
40 }
41 if (strncmp(argv[1], "inf", 3) == 0) {
Simon Glassc8e89ab2016-05-01 11:36:09 -060042 blk_list_devices(IF_TYPE_SCSI);
Simon Glass5c7bf8e2016-05-01 11:35:58 -060043 return 0;
44 }
45 if (strncmp(argv[1], "dev", 3) == 0) {
Simon Glassc8e89ab2016-05-01 11:36:09 -060046 if (blk_print_device_num(IF_TYPE_SCSI, scsi_curr_dev)) {
Simon Glass5c7bf8e2016-05-01 11:35:58 -060047 printf("\nno SCSI devices available\n");
Simon Glassc8e89ab2016-05-01 11:36:09 -060048 return CMD_RET_FAILURE;
wdenke887afc2002-08-27 09:44:07 +000049 }
Simon Glassc8e89ab2016-05-01 11:36:09 -060050
Simon Glass5c7bf8e2016-05-01 11:35:58 -060051 return 0;
52 }
53 if (strncmp(argv[1], "scan", 4) == 0) {
54 scsi_scan(1);
55 return 0;
56 }
57 if (strncmp(argv[1], "part", 4) == 0) {
Simon Glassc8e89ab2016-05-01 11:36:09 -060058 if (blk_list_part(IF_TYPE_SCSI))
Simon Glass5c7bf8e2016-05-01 11:35:58 -060059 printf("\nno SCSI devices available\n");
Simon Glassc8e89ab2016-05-01 11:36:09 -060060 return 0;
Simon Glass5c7bf8e2016-05-01 11:35:58 -060061 }
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);
Simon Glassc8e89ab2016-05-01 11:36:09 -060066
67 if (!blk_show_device(IF_TYPE_SCSI, dev)) {
68 scsi_curr_dev = dev;
69 printf("... is now current device\n");
70 } else {
71 return CMD_RET_FAILURE;
Simon Glass8f81fa92016-05-01 11:35:57 -060072 }
Simon Glass5c7bf8e2016-05-01 11:35:58 -060073 return 0;
74 }
75 if (strncmp(argv[1], "part", 4) == 0) {
76 int dev = (int)simple_strtoul(argv[2], NULL, 10);
Simon Glassc8e89ab2016-05-01 11:36:09 -060077
78 if (blk_print_part_devnum(IF_TYPE_SCSI, dev)) {
79 printf("\nSCSI device %d not available\n",
80 dev);
81 return CMD_RET_FAILURE;
82 }
83 return 0;
Simon Glass5c7bf8e2016-05-01 11:35:58 -060084 }
85 return CMD_RET_USAGE;
86 default:
87 /* at least 4 args */
88 if (strcmp(argv[1], "read") == 0) {
89 ulong addr = simple_strtoul(argv[2], NULL, 16);
90 ulong blk = simple_strtoul(argv[3], NULL, 16);
91 ulong cnt = simple_strtoul(argv[4], NULL, 16);
92 ulong n;
Simon Glassc8e89ab2016-05-01 11:36:09 -060093
Simon Glass5c7bf8e2016-05-01 11:35:58 -060094 printf("\nSCSI read: device %d block # %ld, count %ld ... ",
95 scsi_curr_dev, blk, cnt);
Simon Glassc8e89ab2016-05-01 11:36:09 -060096 n = blk_read_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk,
97 cnt, (ulong *)addr);
Simon Glass5c7bf8e2016-05-01 11:35:58 -060098 printf("%ld blocks read: %s\n", n,
99 n == cnt ? "OK" : "ERROR");
100 return 0;
101 } else if (strcmp(argv[1], "write") == 0) {
102 ulong addr = simple_strtoul(argv[2], NULL, 16);
103 ulong blk = simple_strtoul(argv[3], NULL, 16);
104 ulong cnt = simple_strtoul(argv[4], NULL, 16);
105 ulong n;
Simon Glassc8e89ab2016-05-01 11:36:09 -0600106
Simon Glass5c7bf8e2016-05-01 11:35:58 -0600107 printf("\nSCSI write: device %d block # %ld, count %ld ... ",
108 scsi_curr_dev, blk, cnt);
Simon Glassc8e89ab2016-05-01 11:36:09 -0600109 n = blk_write_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk,
110 cnt, (ulong *)addr);
Simon Glass5c7bf8e2016-05-01 11:35:58 -0600111 printf("%ld blocks written: %s\n", n,
112 n == cnt ? "OK" : "ERROR");
113 return 0;
114 }
Simon Glass8f81fa92016-05-01 11:35:57 -0600115 } /* switch */
116 return CMD_RET_USAGE;
Hung-Te Lin98a6c4e2012-10-29 05:23:46 +0000117}
118
Simon Glass8f81fa92016-05-01 11:35:57 -0600119U_BOOT_CMD(
120 scsi, 5, 1, do_scsi,
121 "SCSI sub-system",
122 "reset - reset SCSI controller\n"
123 "scsi info - show available SCSI devices\n"
124 "scsi scan - (re-)scan SCSI bus\n"
125 "scsi device [dev] - show or set current device\n"
126 "scsi part [dev] - print partition table of one or all SCSI devices\n"
127 "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
128 " to memory address `addr'\n"
129 "scsi write addr blk# cnt - write `cnt' blocks starting at block\n"
130 " `blk#' from memory address `addr'"
131);
132
133U_BOOT_CMD(
134 scsiboot, 3, 1, do_scsiboot,
135 "boot from SCSI device",
136 "loadAddr dev:part"
137);