]>
Commit | Line | Data |
---|---|---|
c7057b52 DL |
1 | /* |
2 | * Copyright (C) 2000-2005, DENX Software Engineering | |
3 | * Wolfgang Denk <[email protected]> | |
4 | * Copyright (C) Procsys. All rights reserved. | |
5 | * Mushtaq Khan <[email protected]> | |
6 | * <[email protected]> | |
7 | * Copyright (C) 2008 Freescale Semiconductor, Inc. | |
8 | * Dave Liu <[email protected]> | |
9 | * | |
1a459660 | 10 | * SPDX-License-Identifier: GPL-2.0+ |
c7057b52 DL |
11 | */ |
12 | ||
13 | #include <common.h> | |
14 | #include <command.h> | |
15 | #include <part.h> | |
16 | #include <sata.h> | |
17 | ||
088f1b19 | 18 | static int sata_curr_device = -1; |
c7057b52 | 19 | |
088f1b19 | 20 | static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
c7057b52 DL |
21 | { |
22 | int rc = 0; | |
23 | ||
d957c28a NK |
24 | if (argc == 2 && strcmp(argv[1], "stop") == 0) |
25 | return sata_stop(); | |
26 | ||
27 | if (argc == 2 && strcmp(argv[1], "init") == 0) { | |
28 | if (sata_curr_device != -1) | |
29 | sata_stop(); | |
30 | ||
cf7e399f | 31 | return sata_initialize(); |
d957c28a | 32 | } |
cf7e399f MF |
33 | |
34 | /* If the user has not yet run `sata init`, do it now */ | |
569460eb | 35 | if (sata_curr_device == -1) |
cf7e399f MF |
36 | if (sata_initialize()) |
37 | return 1; | |
38 | ||
c7057b52 DL |
39 | switch (argc) { |
40 | case 0: | |
41 | case 1: | |
4c12eeb8 | 42 | return CMD_RET_USAGE; |
c7057b52 | 43 | case 2: |
2765c4d1 | 44 | if (strncmp(argv[1], "inf", 3) == 0) { |
d97dc8a0 | 45 | blk_list_devices(IF_TYPE_SATA); |
c7057b52 | 46 | return 0; |
2765c4d1 | 47 | } else if (strncmp(argv[1], "dev", 3) == 0) { |
d97dc8a0 SG |
48 | if (blk_print_device_num(IF_TYPE_SATA, |
49 | sata_curr_device)) { | |
50 | printf("\nno SATA devices available\n"); | |
51 | return CMD_RET_FAILURE; | |
c7057b52 | 52 | } |
c7057b52 | 53 | return 0; |
2765c4d1 | 54 | } else if (strncmp(argv[1], "part", 4) == 0) { |
d97dc8a0 | 55 | if (blk_list_part(IF_TYPE_SATA)) |
c7057b52 | 56 | puts("\nno SATA devices available\n"); |
d97dc8a0 | 57 | return 0; |
c7057b52 | 58 | } |
4c12eeb8 | 59 | return CMD_RET_USAGE; |
c7057b52 DL |
60 | case 3: |
61 | if (strncmp(argv[1], "dev", 3) == 0) { | |
62 | int dev = (int)simple_strtoul(argv[2], NULL, 10); | |
63 | ||
d97dc8a0 SG |
64 | if (!blk_show_device(IF_TYPE_SATA, dev)) { |
65 | sata_curr_device = dev; | |
66 | printf("... is now current device\n"); | |
67 | } else { | |
68 | return CMD_RET_FAILURE; | |
c7057b52 | 69 | } |
c7057b52 DL |
70 | return 0; |
71 | } else if (strncmp(argv[1], "part", 4) == 0) { | |
72 | int dev = (int)simple_strtoul(argv[2], NULL, 10); | |
73 | ||
d97dc8a0 SG |
74 | if (blk_print_part_devnum(IF_TYPE_SATA, dev)) { |
75 | printf("\nSATA device %d not available\n", | |
76 | dev); | |
77 | return CMD_RET_FAILURE; | |
c7057b52 DL |
78 | } |
79 | return rc; | |
80 | } | |
4c12eeb8 | 81 | return CMD_RET_USAGE; |
c7057b52 DL |
82 | |
83 | default: /* at least 4 args */ | |
84 | if (strcmp(argv[1], "read") == 0) { | |
85 | ulong addr = simple_strtoul(argv[2], NULL, 16); | |
86 | ulong cnt = simple_strtoul(argv[4], NULL, 16); | |
87 | ulong n; | |
88 | lbaint_t blk = simple_strtoul(argv[3], NULL, 16); | |
89 | ||
90 | printf("\nSATA read: device %d block # %ld, count %ld ... ", | |
569460eb | 91 | sata_curr_device, blk, cnt); |
c7057b52 | 92 | |
d97dc8a0 SG |
93 | n = blk_read_devnum(IF_TYPE_SATA, sata_curr_device, blk, |
94 | cnt, (ulong *)addr); | |
c7057b52 DL |
95 | |
96 | printf("%ld blocks read: %s\n", | |
97 | n, (n==cnt) ? "OK" : "ERROR"); | |
98 | return (n == cnt) ? 0 : 1; | |
99 | } else if (strcmp(argv[1], "write") == 0) { | |
100 | ulong addr = simple_strtoul(argv[2], NULL, 16); | |
101 | ulong cnt = simple_strtoul(argv[4], NULL, 16); | |
102 | ulong n; | |
103 | ||
104 | lbaint_t blk = simple_strtoul(argv[3], NULL, 16); | |
105 | ||
106 | printf("\nSATA write: device %d block # %ld, count %ld ... ", | |
569460eb | 107 | sata_curr_device, blk, cnt); |
c7057b52 | 108 | |
d97dc8a0 SG |
109 | n = blk_write_devnum(IF_TYPE_SATA, sata_curr_device, |
110 | blk, cnt, (ulong *)addr); | |
c7057b52 DL |
111 | |
112 | printf("%ld blocks written: %s\n", | |
113 | n, (n == cnt) ? "OK" : "ERROR"); | |
114 | return (n == cnt) ? 0 : 1; | |
115 | } else { | |
4c12eeb8 | 116 | return CMD_RET_USAGE; |
c7057b52 DL |
117 | } |
118 | ||
119 | return rc; | |
120 | } | |
121 | } | |
122 | ||
123 | U_BOOT_CMD( | |
124 | sata, 5, 1, do_sata, | |
2fb2604d | 125 | "SATA sub system", |
85dafbb8 | 126 | "init - init SATA sub system\n" |
d957c28a | 127 | "sata stop - disable SATA sub system\n" |
c7057b52 DL |
128 | "sata info - show available SATA devices\n" |
129 | "sata device [dev] - show or set current device\n" | |
130 | "sata part [dev] - print partition table\n" | |
131 | "sata read addr blk# cnt\n" | |
a89c33db WD |
132 | "sata write addr blk# cnt" |
133 | ); |