Tom Rini | 83d290c | 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 | */ |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 10 | #include <common.h> |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 11 | #include <blk.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 12 | #include <command.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 13 | #include <scsi.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 14 | |
| 15 | static int scsi_curr_dev; /* current device */ |
| 16 | |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 17 | /* |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 18 | * scsi boot command intepreter. Derived from diskboot |
| 19 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 20 | static int do_scsiboot(struct cmd_tbl *cmdtp, int flag, int argc, |
| 21 | char *const argv[]) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 22 | { |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 23 | return common_diskboot(cmdtp, "scsi", argc, argv); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 26 | /* |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 27 | * scsi command intepreter |
| 28 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 29 | static int do_scsi(struct cmd_tbl *cmdtp, int flag, int argc, |
| 30 | char *const argv[]) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 31 | { |
Michal Simek | c002e39 | 2016-11-30 12:12:31 +0100 | [diff] [blame] | 32 | int ret; |
| 33 | |
Simon Glass | 1eaadd3 | 2017-07-29 11:34:56 -0600 | [diff] [blame] | 34 | if (argc == 2) { |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 35 | if (strncmp(argv[1], "res", 3) == 0) { |
| 36 | printf("\nReset SCSI\n"); |
Bin Meng | db13a76 | 2017-06-17 06:36:00 -0700 | [diff] [blame] | 37 | #ifndef CONFIG_DM_SCSI |
Simon Glass | 4682c8a | 2017-06-14 21:28:40 -0600 | [diff] [blame] | 38 | scsi_bus_reset(NULL); |
Bin Meng | db13a76 | 2017-06-17 06:36:00 -0700 | [diff] [blame] | 39 | #endif |
Simon Glass | 8eab1a5 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 40 | ret = scsi_scan(true); |
Michal Simek | c002e39 | 2016-11-30 12:12:31 +0100 | [diff] [blame] | 41 | if (ret) |
| 42 | return CMD_RET_FAILURE; |
| 43 | return ret; |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 44 | } |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 45 | if (strncmp(argv[1], "scan", 4) == 0) { |
Simon Glass | 8eab1a5 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 46 | ret = scsi_scan(true); |
Michal Simek | c002e39 | 2016-11-30 12:12:31 +0100 | [diff] [blame] | 47 | if (ret) |
| 48 | return CMD_RET_FAILURE; |
| 49 | return ret; |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 50 | } |
Simon Glass | 1eaadd3 | 2017-07-29 11:34:56 -0600 | [diff] [blame] | 51 | } |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 52 | |
Simon Glass | e33a5c6 | 2022-08-11 19:34:59 -0600 | [diff] [blame] | 53 | return blk_common_cmd(argc, argv, UCLASS_SCSI, &scsi_curr_dev); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Tom Rini | ba52426 | 2016-03-16 09:45:03 -0400 | [diff] [blame] | 56 | U_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 | |
| 70 | U_BOOT_CMD( |
| 71 | scsiboot, 3, 1, do_scsiboot, |
| 72 | "boot from SCSI device", |
| 73 | "loadAddr dev:part" |
| 74 | ); |