blob: 4549995ba73c4b5f2bf5034442d79c18ce47f256 [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>
Simon Glasse6f6f9e2020-05-10 11:39:58 -060011#include <blk.h>
wdenke887afc2002-08-27 09:44:07 +000012#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 Glass11f610e2016-05-01 11:36:09 -060017/*
wdenke887afc2002-08-27 09:44:07 +000018 * scsi boot command intepreter. Derived from diskboot
19 */
Simon Glass09140112020-05-10 11:40:03 -060020static int do_scsiboot(struct cmd_tbl *cmdtp, int flag, int argc,
21 char *const argv[])
wdenke887afc2002-08-27 09:44:07 +000022{
Rob Herring7405a132012-09-21 04:02:30 +000023 return common_diskboot(cmdtp, "scsi", argc, argv);
wdenke887afc2002-08-27 09:44:07 +000024}
25
Simon Glass11f610e2016-05-01 11:36:09 -060026/*
wdenke887afc2002-08-27 09:44:07 +000027 * scsi command intepreter
28 */
Simon Glass09140112020-05-10 11:40:03 -060029static int do_scsi(struct cmd_tbl *cmdtp, int flag, int argc,
30 char *const argv[])
wdenke887afc2002-08-27 09:44:07 +000031{
Michal Simekc002e392016-11-30 12:12:31 +010032 int ret;
33
Simon Glass1eaadd32017-07-29 11:34:56 -060034 if (argc == 2) {
Simon Glassf1d4d932016-05-01 11:35:58 -060035 if (strncmp(argv[1], "res", 3) == 0) {
36 printf("\nReset SCSI\n");
Bin Mengdb13a762017-06-17 06:36:00 -070037#ifndef CONFIG_DM_SCSI
Simon Glass4682c8a2017-06-14 21:28:40 -060038 scsi_bus_reset(NULL);
Bin Mengdb13a762017-06-17 06:36:00 -070039#endif
Simon Glass8eab1a52017-06-14 21:28:41 -060040 ret = scsi_scan(true);
Michal Simekc002e392016-11-30 12:12:31 +010041 if (ret)
42 return CMD_RET_FAILURE;
43 return ret;
Simon Glassf1d4d932016-05-01 11:35:58 -060044 }
Simon Glassf1d4d932016-05-01 11:35:58 -060045 if (strncmp(argv[1], "scan", 4) == 0) {
Simon Glass8eab1a52017-06-14 21:28:41 -060046 ret = scsi_scan(true);
Michal Simekc002e392016-11-30 12:12:31 +010047 if (ret)
48 return CMD_RET_FAILURE;
49 return ret;
Simon Glassf1d4d932016-05-01 11:35:58 -060050 }
Simon Glass1eaadd32017-07-29 11:34:56 -060051 }
Simon Glass11f610e2016-05-01 11:36:09 -060052
Simon Glasse33a5c62022-08-11 19:34:59 -060053 return blk_common_cmd(argc, argv, UCLASS_SCSI, &scsi_curr_dev);
wdenke887afc2002-08-27 09:44:07 +000054}
55
Tom Riniba524262016-03-16 09:45:03 -040056U_BOOT_CMD(
57 scsi, 5, 1, do_scsi,
58 "SCSI sub-system",
59 "reset - reset SCSI controller\n"
60 "scsi info - show available SCSI devices\n"
61 "scsi scan - (re-)scan SCSI bus\n"
62 "scsi device [dev] - show or set current device\n"
63 "scsi part [dev] - print partition table of one or all SCSI devices\n"
64 "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
65 " to memory address `addr'\n"
66 "scsi write addr blk# cnt - write `cnt' blocks starting at block\n"
67 " `blk#' from memory address `addr'"
68);
69
70U_BOOT_CMD(
71 scsiboot, 3, 1, do_scsiboot,
72 "boot from SCSI device",
73 "loadAddr dev:part"
74);