blob: b9d086fb6b1943130193d02b20aef5d4905286f5 [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 */
Michal Simekff238112016-11-30 12:18:36 +010020static int 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 */
Michal Simekff238112016-11-30 12:18:36 +010028static int do_scsi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
wdenke887afc2002-08-27 09:44:07 +000029{
Michal Simek5dc196f2016-11-30 12:12:31 +010030 int ret;
31
Simon Glass868a48c2017-07-29 11:34:56 -060032 if (argc == 2) {
Simon Glass5c7bf8e2016-05-01 11:35:58 -060033 if (strncmp(argv[1], "res", 3) == 0) {
34 printf("\nReset SCSI\n");
Bin Meng8aa95762017-06-17 06:36:00 -070035#ifndef CONFIG_DM_SCSI
Simon Glass11b2b622017-06-14 21:28:40 -060036 scsi_bus_reset(NULL);
Bin Meng8aa95762017-06-17 06:36:00 -070037#endif
Simon Glass48228732017-06-14 21:28:41 -060038 ret = scsi_scan(true);
Michal Simek5dc196f2016-11-30 12:12:31 +010039 if (ret)
40 return CMD_RET_FAILURE;
41 return ret;
Simon Glass5c7bf8e2016-05-01 11:35:58 -060042 }
Simon Glass5c7bf8e2016-05-01 11:35:58 -060043 if (strncmp(argv[1], "scan", 4) == 0) {
Simon Glass48228732017-06-14 21:28:41 -060044 ret = scsi_scan(true);
Michal Simek5dc196f2016-11-30 12:12:31 +010045 if (ret)
46 return CMD_RET_FAILURE;
47 return ret;
Simon Glass5c7bf8e2016-05-01 11:35:58 -060048 }
Simon Glass868a48c2017-07-29 11:34:56 -060049 }
Simon Glassc8e89ab2016-05-01 11:36:09 -060050
Simon Glass868a48c2017-07-29 11:34:56 -060051 return blk_common_cmd(argc, argv, IF_TYPE_SCSI, &scsi_curr_dev);
Hung-Te Lin98a6c4e2012-10-29 05:23:46 +000052}
53
Simon Glass8f81fa92016-05-01 11:35:57 -060054U_BOOT_CMD(
55 scsi, 5, 1, do_scsi,
56 "SCSI sub-system",
57 "reset - reset SCSI controller\n"
58 "scsi info - show available SCSI devices\n"
59 "scsi scan - (re-)scan SCSI bus\n"
60 "scsi device [dev] - show or set current device\n"
61 "scsi part [dev] - print partition table of one or all SCSI devices\n"
62 "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
63 " to memory address `addr'\n"
64 "scsi write addr blk# cnt - write `cnt' blocks starting at block\n"
65 " `blk#' from memory address `addr'"
66);
67
68U_BOOT_CMD(
69 scsiboot, 3, 1, do_scsiboot,
70 "boot from SCSI device",
71 "loadAddr dev:part"
72);