Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2001 |
| 4 | * Denis Peter, MPL AG Switzerland |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * SCSI support. |
| 9 | */ |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 10 | #include <blk.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 11 | #include <command.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 12 | #include <scsi.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 13 | |
| 14 | static int scsi_curr_dev; /* current device */ |
| 15 | |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 16 | /* |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 17 | * scsi boot command intepreter. Derived from diskboot |
| 18 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 19 | static int do_scsiboot(struct cmd_tbl *cmdtp, int flag, int argc, |
| 20 | char *const argv[]) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 21 | { |
Rob Herring | a20cbf9 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 22 | return common_diskboot(cmdtp, "scsi", argc, argv); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 25 | /* |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 26 | * scsi command intepreter |
| 27 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 28 | static int do_scsi(struct cmd_tbl *cmdtp, int flag, int argc, |
| 29 | char *const argv[]) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 30 | { |
Michal Simek | 5dc196f | 2016-11-30 12:12:31 +0100 | [diff] [blame] | 31 | int ret; |
| 32 | |
Simon Glass | 868a48c | 2017-07-29 11:34:56 -0600 | [diff] [blame] | 33 | if (argc == 2) { |
Simon Glass | 5c7bf8e | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 34 | if (strncmp(argv[1], "res", 3) == 0) { |
| 35 | printf("\nReset SCSI\n"); |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 36 | ret = scsi_scan(true); |
Michal Simek | 5dc196f | 2016-11-30 12:12:31 +0100 | [diff] [blame] | 37 | if (ret) |
| 38 | return CMD_RET_FAILURE; |
| 39 | return ret; |
Simon Glass | 5c7bf8e | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 40 | } |
Simon Glass | 5c7bf8e | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 41 | if (strncmp(argv[1], "scan", 4) == 0) { |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 42 | ret = scsi_scan(true); |
Michal Simek | 5dc196f | 2016-11-30 12:12:31 +0100 | [diff] [blame] | 43 | if (ret) |
| 44 | return CMD_RET_FAILURE; |
| 45 | return ret; |
Simon Glass | 5c7bf8e | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 46 | } |
Simon Glass | 868a48c | 2017-07-29 11:34:56 -0600 | [diff] [blame] | 47 | } |
Simon Glass | c8e89ab | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 48 | |
Simon Glass | dbfa32c | 2022-08-11 19:34:59 -0600 | [diff] [blame] | 49 | return blk_common_cmd(argc, argv, UCLASS_SCSI, &scsi_curr_dev); |
Hung-Te Lin | 98a6c4e | 2012-10-29 05:23:46 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Simon Glass | 8f81fa9 | 2016-05-01 11:35:57 -0600 | [diff] [blame] | 52 | U_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 | |
| 66 | U_BOOT_CMD( |
| 67 | scsiboot, 3, 1, do_scsiboot, |
| 68 | "boot from SCSI device", |
| 69 | "loadAddr dev:part" |
| 70 | ); |