]>
git.ipfire.org Git - people/ms/u-boot.git/blob - cmd/sata.c
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() < 0) ?
32 CMD_RET_FAILURE
: CMD_RET_SUCCESS
;
35 /* If the user has not yet run `sata init`, do it now */
36 if (sata_curr_device
== -1) {
37 rc
= sata_initialize();
39 return CMD_RET_FAILURE
;
40 sata_curr_device
= rc
;
48 if (strncmp(argv
[1], "inf", 3) == 0) {
49 blk_list_devices(IF_TYPE_SATA
);
51 } else if (strncmp(argv
[1], "dev", 3) == 0) {
52 if (blk_print_device_num(IF_TYPE_SATA
,
54 printf("\nno SATA devices available\n");
55 return CMD_RET_FAILURE
;
58 } else if (strncmp(argv
[1], "part", 4) == 0) {
59 if (blk_list_part(IF_TYPE_SATA
))
60 puts("\nno SATA devices available\n");
65 if (strncmp(argv
[1], "dev", 3) == 0) {
66 int dev
= (int)simple_strtoul(argv
[2], NULL
, 10);
68 if (!blk_show_device(IF_TYPE_SATA
, dev
)) {
69 sata_curr_device
= dev
;
70 printf("... is now current device\n");
72 return CMD_RET_FAILURE
;
75 } else if (strncmp(argv
[1], "part", 4) == 0) {
76 int dev
= (int)simple_strtoul(argv
[2], NULL
, 10);
78 if (blk_print_part_devnum(IF_TYPE_SATA
, dev
)) {
79 printf("\nSATA device %d not available\n",
81 return CMD_RET_FAILURE
;
87 default: /* at least 4 args */
88 if (strcmp(argv
[1], "read") == 0) {
89 ulong addr
= simple_strtoul(argv
[2], NULL
, 16);
90 ulong cnt
= simple_strtoul(argv
[4], NULL
, 16);
92 lbaint_t blk
= simple_strtoul(argv
[3], NULL
, 16);
94 printf("\nSATA read: device %d block # %ld, count %ld ... ",
95 sata_curr_device
, blk
, cnt
);
97 n
= blk_read_devnum(IF_TYPE_SATA
, sata_curr_device
, blk
,
100 printf("%ld blocks read: %s\n",
101 n
, (n
==cnt
) ? "OK" : "ERROR");
102 return (n
== cnt
) ? 0 : 1;
103 } else if (strcmp(argv
[1], "write") == 0) {
104 ulong addr
= simple_strtoul(argv
[2], NULL
, 16);
105 ulong cnt
= simple_strtoul(argv
[4], NULL
, 16);
108 lbaint_t blk
= simple_strtoul(argv
[3], NULL
, 16);
110 printf("\nSATA write: device %d block # %ld, count %ld ... ",
111 sata_curr_device
, blk
, cnt
);
113 n
= blk_write_devnum(IF_TYPE_SATA
, sata_curr_device
,
114 blk
, cnt
, (ulong
*)addr
);
116 printf("%ld blocks written: %s\n",
117 n
, (n
== cnt
) ? "OK" : "ERROR");
118 return (n
== cnt
) ? 0 : 1;
120 return CMD_RET_USAGE
;
130 "init - init SATA sub system\n"
131 "sata stop - disable SATA sub system\n"
132 "sata info - show available SATA devices\n"
133 "sata device [dev] - show or set current device\n"
134 "sata part [dev] - print partition table\n"
135 "sata read addr blk# cnt\n"
136 "sata write addr blk# cnt"