blob: c286bdc072605796614c817fea43f4cf5fb6d968 [file] [log] [blame]
Tom Rini10e47792018-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 */
Simon Glass655306c2020-05-10 11:39:58 -060010#include <blk.h>
wdenke887afc2002-08-27 09:44:07 +000011#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 Glassc8e89ab2016-05-01 11:36:09 -060016/*
wdenke887afc2002-08-27 09:44:07 +000017 * scsi boot command intepreter. Derived from diskboot
18 */
Simon Glassed38aef2020-05-10 11:40:03 -060019static int do_scsiboot(struct cmd_tbl *cmdtp, int flag, int argc,
20 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 Glassed38aef2020-05-10 11:40:03 -060028static int do_scsi(struct cmd_tbl *cmdtp, int flag, int argc,
29 char *const argv[])
wdenke887afc2002-08-27 09:44:07 +000030{
Michal Simek5dc196f2016-11-30 12:12:31 +010031 int ret;
32
Simon Glass868a48c2017-07-29 11:34:56 -060033 if (argc == 2) {
Simon Glass5c7bf8e2016-05-01 11:35:58 -060034 if (strncmp(argv[1], "res", 3) == 0) {
35 printf("\nReset SCSI\n");
Simon Glass48228732017-06-14 21:28:41 -060036 ret = scsi_scan(true);
Michal Simek5dc196f2016-11-30 12:12:31 +010037 if (ret)
38 return CMD_RET_FAILURE;
39 return ret;
Simon Glass5c7bf8e2016-05-01 11:35:58 -060040 }
Simon Glass5c7bf8e2016-05-01 11:35:58 -060041 if (strncmp(argv[1], "scan", 4) == 0) {
Simon Glass48228732017-06-14 21:28:41 -060042 ret = scsi_scan(true);
Michal Simek5dc196f2016-11-30 12:12:31 +010043 if (ret)
44 return CMD_RET_FAILURE;
45 return ret;
Simon Glass5c7bf8e2016-05-01 11:35:58 -060046 }
Simon Glass868a48c2017-07-29 11:34:56 -060047 }
Simon Glassc8e89ab2016-05-01 11:36:09 -060048
Simon Glassdbfa32c2022-08-11 19:34:59 -060049 return blk_common_cmd(argc, argv, UCLASS_SCSI, &scsi_curr_dev);
Hung-Te Lin98a6c4e2012-10-29 05:23:46 +000050}
51
Simon Glass8f81fa92016-05-01 11:35:57 -060052U_BOOT_CMD(
53 scsi, 5, 1, do_scsi,
54 "SCSI sub-system",
55 "reset - reset SCSI controller\n"
56 "scsi info - show available SCSI devices\n"
57 "scsi scan - (re-)scan SCSI bus\n"
58 "scsi device [dev] - show or set current device\n"
59 "scsi part [dev] - print partition table of one or all SCSI devices\n"
60 "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
61 " to memory address `addr'\n"
62 "scsi write addr blk# cnt - write `cnt' blocks starting at block\n"
63 " `blk#' from memory address `addr'"
64);
65
66U_BOOT_CMD(
67 scsiboot, 3, 1, do_scsiboot,
68 "boot from SCSI device",
69 "loadAddr dev:part"
70);