2 * Copyright (C) 2000-2005, DENX Software Engineering
3 * Wolfgang Denk <wd@denx.de>
4 * Copyright (C) Procsys. All rights reserved.
5 * Mushtaq Khan <mushtaq_k@procsys.com>
6 * <mushtaqk_921@yahoo.co.in>
7 * Copyright (C) 2008 Freescale Semiconductor, Inc.
8 * Dave Liu <daveliu@freescale.com>
10 * SPDX-License-Identifier: GPL-2.0+
18 static int sata_curr_device = -1;
20 static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
24 if (argc == 2 && strcmp(argv[1], "stop") == 0)
27 if (argc == 2 && strcmp(argv[1], "init") == 0) {
28 if (sata_curr_device != -1)
31 return sata_initialize();
34 /* If the user has not yet run `sata init`, do it now */
35 if (sata_curr_device == -1) {
36 rc = sata_initialize();
39 sata_curr_device = rc;
47 if (strncmp(argv[1], "inf", 3) == 0) {
48 blk_list_devices(IF_TYPE_SATA);
50 } else if (strncmp(argv[1], "dev", 3) == 0) {
51 if (blk_print_device_num(IF_TYPE_SATA,
53 printf("\nno SATA devices available\n");
54 return CMD_RET_FAILURE;
57 } else if (strncmp(argv[1], "part", 4) == 0) {
58 if (blk_list_part(IF_TYPE_SATA))
59 puts("\nno SATA devices available\n");
64 if (strncmp(argv[1], "dev", 3) == 0) {
65 int dev = (int)simple_strtoul(argv[2], NULL, 10);
67 if (!blk_show_device(IF_TYPE_SATA, dev)) {
68 sata_curr_device = dev;
69 printf("... is now current device\n");
71 return CMD_RET_FAILURE;
74 } else if (strncmp(argv[1], "part", 4) == 0) {
75 int dev = (int)simple_strtoul(argv[2], NULL, 10);
77 if (blk_print_part_devnum(IF_TYPE_SATA, dev)) {
78 printf("\nSATA device %d not available\n",
80 return CMD_RET_FAILURE;
86 default: /* at least 4 args */
87 if (strcmp(argv[1], "read") == 0) {
88 ulong addr = simple_strtoul(argv[2], NULL, 16);
89 ulong cnt = simple_strtoul(argv[4], NULL, 16);
91 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
93 printf("\nSATA read: device %d block # %ld, count %ld ... ",
94 sata_curr_device, blk, cnt);
96 n = blk_read_devnum(IF_TYPE_SATA, sata_curr_device, blk,
99 printf("%ld blocks read: %s\n",
100 n, (n==cnt) ? "OK" : "ERROR");
101 return (n == cnt) ? 0 : 1;
102 } else if (strcmp(argv[1], "write") == 0) {
103 ulong addr = simple_strtoul(argv[2], NULL, 16);
104 ulong cnt = simple_strtoul(argv[4], NULL, 16);
107 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
109 printf("\nSATA write: device %d block # %ld, count %ld ... ",
110 sata_curr_device, blk, cnt);
112 n = blk_write_devnum(IF_TYPE_SATA, sata_curr_device,
113 blk, cnt, (ulong *)addr);
115 printf("%ld blocks written: %s\n",
116 n, (n == cnt) ? "OK" : "ERROR");
117 return (n == cnt) ? 0 : 1;
119 return CMD_RET_USAGE;
129 "init - init SATA sub system\n"
130 "sata stop - disable SATA sub system\n"
131 "sata info - show available SATA devices\n"
132 "sata device [dev] - show or set current device\n"
133 "sata part [dev] - print partition table\n"
134 "sata read addr blk# cnt\n"
135 "sata write addr blk# cnt"