blob: 67de1a3bdc2c0085f393d18ba5f8d509348fb1d3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenke887afc2002-08-27 09:44:07 +00002/*
3 * (C) Copyright 2001
4 * Denis Peter, MPL AG Switzerland
wdenke887afc2002-08-27 09:44:07 +00005 */
6
7/*
8 * SCSI support.
9 */
wdenke887afc2002-08-27 09:44:07 +000010#include <common.h>
11#include <command.h>
wdenke887afc2002-08-27 09:44:07 +000012#include <scsi.h>
wdenke887afc2002-08-27 09:44:07 +000013
14static int scsi_curr_dev; /* current device */
15
Simon Glass11f610e2016-05-01 11:36:09 -060016/*
wdenke887afc2002-08-27 09:44:07 +000017 * scsi boot command intepreter. Derived from diskboot
18 */
Michal Simek861fe652016-11-30 12:18:36 +010019static int do_scsiboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
wdenke887afc2002-08-27 09:44:07 +000020{
Rob Herring7405a132012-09-21 04:02:30 +000021 return common_diskboot(cmdtp, "scsi", argc, argv);
wdenke887afc2002-08-27 09:44:07 +000022}
23
Simon Glass11f610e2016-05-01 11:36:09 -060024/*
wdenke887afc2002-08-27 09:44:07 +000025 * scsi command intepreter
26 */
Michal Simek861fe652016-11-30 12:18:36 +010027static int do_scsi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
wdenke887afc2002-08-27 09:44:07 +000028{
Michal Simekc002e392016-11-30 12:12:31 +010029 int ret;
30
Simon Glass1eaadd32017-07-29 11:34:56 -060031 if (argc == 2) {
Simon Glassf1d4d932016-05-01 11:35:58 -060032 if (strncmp(argv[1], "res", 3) == 0) {
33 printf("\nReset SCSI\n");
Bin Mengdb13a762017-06-17 06:36:00 -070034#ifndef CONFIG_DM_SCSI
Simon Glass4682c8a2017-06-14 21:28:40 -060035 scsi_bus_reset(NULL);
Bin Mengdb13a762017-06-17 06:36:00 -070036#endif
Simon Glass8eab1a52017-06-14 21:28:41 -060037 ret = scsi_scan(true);
Michal Simekc002e392016-11-30 12:12:31 +010038 if (ret)
39 return CMD_RET_FAILURE;
40 return ret;
Simon Glassf1d4d932016-05-01 11:35:58 -060041 }
Simon Glassf1d4d932016-05-01 11:35:58 -060042 if (strncmp(argv[1], "scan", 4) == 0) {
Simon Glass8eab1a52017-06-14 21:28:41 -060043 ret = scsi_scan(true);
Michal Simekc002e392016-11-30 12:12:31 +010044 if (ret)
45 return CMD_RET_FAILURE;
46 return ret;
Simon Glassf1d4d932016-05-01 11:35:58 -060047 }
Simon Glass1eaadd32017-07-29 11:34:56 -060048 }
Simon Glass11f610e2016-05-01 11:36:09 -060049
Simon Glass1eaadd32017-07-29 11:34:56 -060050 return blk_common_cmd(argc, argv, IF_TYPE_SCSI, &scsi_curr_dev);
wdenke887afc2002-08-27 09:44:07 +000051}
52
Tom Riniba524262016-03-16 09:45:03 -040053U_BOOT_CMD(
54 scsi, 5, 1, do_scsi,
55 "SCSI sub-system",
56 "reset - reset SCSI controller\n"
57 "scsi info - show available SCSI devices\n"
58 "scsi scan - (re-)scan SCSI bus\n"
59 "scsi device [dev] - show or set current device\n"
60 "scsi part [dev] - print partition table of one or all SCSI devices\n"
61 "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
62 " to memory address `addr'\n"
63 "scsi write addr blk# cnt - write `cnt' blocks starting at block\n"
64 " `blk#' from memory address `addr'"
65);
66
67U_BOOT_CMD(
68 scsiboot, 3, 1, do_scsiboot,
69 "boot from SCSI device",
70 "loadAddr dev:part"
71);