wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Denis Peter, MPL AG Switzerland |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * SCSI support. |
| 10 | */ |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 11 | #include <common.h> |
| 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 | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 20 | int do_scsiboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 21 | { |
Rob Herring | 7405a13 | 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 | 11f610e | 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 | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 28 | int do_scsi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 29 | { |
| 30 | switch (argc) { |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 31 | case 0: |
| 32 | case 1: |
| 33 | return CMD_RET_USAGE; |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 34 | case 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"); |
| 37 | scsi_bus_reset(); |
| 38 | scsi_scan(1); |
| 39 | return 0; |
| 40 | } |
| 41 | if (strncmp(argv[1], "inf", 3) == 0) { |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 42 | blk_list_devices(IF_TYPE_SCSI); |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 43 | return 0; |
| 44 | } |
| 45 | if (strncmp(argv[1], "dev", 3) == 0) { |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 46 | if (blk_print_device_num(IF_TYPE_SCSI, scsi_curr_dev)) { |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 47 | printf("\nno SCSI devices available\n"); |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 48 | return CMD_RET_FAILURE; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 49 | } |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 50 | |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | if (strncmp(argv[1], "scan", 4) == 0) { |
| 54 | scsi_scan(1); |
| 55 | return 0; |
| 56 | } |
| 57 | if (strncmp(argv[1], "part", 4) == 0) { |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 58 | if (blk_list_part(IF_TYPE_SCSI)) |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 59 | printf("\nno SCSI devices available\n"); |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 60 | return 0; |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 61 | } |
| 62 | return CMD_RET_USAGE; |
| 63 | case 3: |
| 64 | if (strncmp(argv[1], "dev", 3) == 0) { |
| 65 | int dev = (int)simple_strtoul(argv[2], NULL, 10); |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 66 | |
| 67 | if (!blk_show_device(IF_TYPE_SCSI, dev)) { |
| 68 | scsi_curr_dev = dev; |
| 69 | printf("... is now current device\n"); |
| 70 | } else { |
| 71 | return CMD_RET_FAILURE; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 72 | } |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 73 | return 0; |
| 74 | } |
| 75 | if (strncmp(argv[1], "part", 4) == 0) { |
| 76 | int dev = (int)simple_strtoul(argv[2], NULL, 10); |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 77 | |
| 78 | if (blk_print_part_devnum(IF_TYPE_SCSI, dev)) { |
| 79 | printf("\nSCSI device %d not available\n", |
| 80 | dev); |
| 81 | return CMD_RET_FAILURE; |
| 82 | } |
| 83 | return 0; |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 84 | } |
| 85 | return CMD_RET_USAGE; |
| 86 | default: |
| 87 | /* at least 4 args */ |
| 88 | if (strcmp(argv[1], "read") == 0) { |
| 89 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 90 | ulong blk = simple_strtoul(argv[3], NULL, 16); |
| 91 | ulong cnt = simple_strtoul(argv[4], NULL, 16); |
| 92 | ulong n; |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 93 | |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 94 | printf("\nSCSI read: device %d block # %ld, count %ld ... ", |
| 95 | scsi_curr_dev, blk, cnt); |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 96 | n = blk_read_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk, |
| 97 | cnt, (ulong *)addr); |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 98 | printf("%ld blocks read: %s\n", n, |
| 99 | n == cnt ? "OK" : "ERROR"); |
| 100 | return 0; |
| 101 | } else if (strcmp(argv[1], "write") == 0) { |
| 102 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 103 | ulong blk = simple_strtoul(argv[3], NULL, 16); |
| 104 | ulong cnt = simple_strtoul(argv[4], NULL, 16); |
| 105 | ulong n; |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 106 | |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 107 | printf("\nSCSI write: device %d block # %ld, count %ld ... ", |
| 108 | scsi_curr_dev, blk, cnt); |
Simon Glass | 11f610e | 2016-05-01 11:36:09 -0600 | [diff] [blame] | 109 | n = blk_write_devnum(IF_TYPE_SCSI, scsi_curr_dev, blk, |
| 110 | cnt, (ulong *)addr); |
Simon Glass | f1d4d93 | 2016-05-01 11:35:58 -0600 | [diff] [blame] | 111 | printf("%ld blocks written: %s\n", n, |
| 112 | n == cnt ? "OK" : "ERROR"); |
| 113 | return 0; |
| 114 | } |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 115 | } /* switch */ |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 116 | return CMD_RET_USAGE; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Tom Rini | ba52426 | 2016-03-16 09:45:03 -0400 | [diff] [blame] | 119 | U_BOOT_CMD( |
| 120 | scsi, 5, 1, do_scsi, |
| 121 | "SCSI sub-system", |
| 122 | "reset - reset SCSI controller\n" |
| 123 | "scsi info - show available SCSI devices\n" |
| 124 | "scsi scan - (re-)scan SCSI bus\n" |
| 125 | "scsi device [dev] - show or set current device\n" |
| 126 | "scsi part [dev] - print partition table of one or all SCSI devices\n" |
| 127 | "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" |
| 128 | " to memory address `addr'\n" |
| 129 | "scsi write addr blk# cnt - write `cnt' blocks starting at block\n" |
| 130 | " `blk#' from memory address `addr'" |
| 131 | ); |
| 132 | |
| 133 | U_BOOT_CMD( |
| 134 | scsiboot, 3, 1, do_scsiboot, |
| 135 | "boot from SCSI device", |
| 136 | "loadAddr dev:part" |
| 137 | ); |