Blame view

cmd/ide.c 4 KB
c609719b8   wdenk   Initial revision
1
  /*
34c202c7e   Wolfgang Denk   common/cmd_ide.c:...
2
   * (C) Copyright 2000-2011
c609719b8   wdenk   Initial revision
3
4
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   *
1a4596601   Wolfgang Denk   Add GPL-2.0+ SPDX...
5
   * SPDX-License-Identifier:	GPL-2.0+
c609719b8   wdenk   Initial revision
6
7
8
9
10
   */
  
  /*
   * IDE support
   */
113bfe48b   Albert Aribaud   cmd_ide: add supp...
11

c609719b8   wdenk   Initial revision
12
  #include <common.h>
2a981dc2c   Simon Glass   dm: block: Adjust...
13
  #include <blk.h>
c609719b8   wdenk   Initial revision
14
15
16
17
18
  #include <config.h>
  #include <watchdog.h>
  #include <command.h>
  #include <image.h>
  #include <asm/byteorder.h>
f98984cb1   Heiko Schocher   IDE: - make ide_i...
19
  #include <asm/io.h>
735dd97b1   Grant Likely   [PATCH 1_4] Merge...
20

c609719b8   wdenk   Initial revision
21
22
23
  #if defined(CONFIG_IDE_8xx_DIRECT) || defined(CONFIG_IDE_PCMCIA)
  # include <pcmcia.h>
  #endif
735dd97b1   Grant Likely   [PATCH 1_4] Merge...
24

c609719b8   wdenk   Initial revision
25
26
  #include <ide.h>
  #include <ata.h>
735dd97b1   Grant Likely   [PATCH 1_4] Merge...
27

c609719b8   wdenk   Initial revision
28
29
30
  #ifdef CONFIG_STATUS_LED
  # include <status_led.h>
  #endif
735dd97b1   Grant Likely   [PATCH 1_4] Merge...
31

c609719b8   wdenk   Initial revision
32
33
  /* Current I/O Device	*/
  static int curr_device = -1;
ed73508de   Simon Glass   dm: ide: Remove t...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  {
  	int rcode = 0;
  
  	switch (argc) {
  	case 0:
  	case 1:
  		return CMD_RET_USAGE;
  	case 2:
  		if (strncmp(argv[1], "res", 3) == 0) {
  			puts("
  Reset IDE"
  #ifdef CONFIG_IDE_8xx_DIRECT
  			     " on PCMCIA " PCMCIA_SLOT_MSG
  #endif
  			     ": ");
  
  			ide_init();
  			return 0;
  		} else if (strncmp(argv[1], "inf", 3) == 0) {
e9be1ee75   Simon Glass   dm: ide: Separate...
54
  			blk_list_devices(IF_TYPE_IDE);
ed73508de   Simon Glass   dm: ide: Remove t...
55
56
57
  			return 0;
  
  		} else if (strncmp(argv[1], "dev", 3) == 0) {
e9be1ee75   Simon Glass   dm: ide: Separate...
58
59
60
61
62
  			if (blk_print_device_num(IF_TYPE_IDE, curr_device)) {
  				printf("
  no IDE devices available
  ");
  				return CMD_RET_FAILURE;
ed73508de   Simon Glass   dm: ide: Remove t...
63
  			}
e9be1ee75   Simon Glass   dm: ide: Separate...
64

ed73508de   Simon Glass   dm: ide: Remove t...
65
66
  			return 0;
  		} else if (strncmp(argv[1], "part", 4) == 0) {
e9be1ee75   Simon Glass   dm: ide: Separate...
67
68
69
70
71
  			if (blk_list_part(IF_TYPE_IDE))
  				printf("
  no IDE devices available
  ");
  			return 1;
ed73508de   Simon Glass   dm: ide: Remove t...
72
73
74
75
76
  		}
  		return CMD_RET_USAGE;
  	case 3:
  		if (strncmp(argv[1], "dev", 3) == 0) {
  			int dev = (int)simple_strtoul(argv[2], NULL, 10);
c609719b8   wdenk   Initial revision
77

e9be1ee75   Simon Glass   dm: ide: Separate...
78
79
80
81
82
83
  			if (!blk_show_device(IF_TYPE_IDE, dev)) {
  				curr_device = dev;
  				printf("... is now current device
  ");
  			} else {
  				return CMD_RET_FAILURE;
ed73508de   Simon Glass   dm: ide: Remove t...
84
  			}
ed73508de   Simon Glass   dm: ide: Remove t...
85
86
87
  			return 0;
  		} else if (strncmp(argv[1], "part", 4) == 0) {
  			int dev = (int)simple_strtoul(argv[2], NULL, 10);
c609719b8   wdenk   Initial revision
88

e9be1ee75   Simon Glass   dm: ide: Separate...
89
90
91
92
93
  			if (blk_print_part_devnum(IF_TYPE_IDE, dev)) {
  				printf("
  IDE device %d not available
  ", dev);
  				return CMD_RET_FAILURE;
ed73508de   Simon Glass   dm: ide: Remove t...
94
  			}
e9be1ee75   Simon Glass   dm: ide: Separate...
95
  			return 1;
ed73508de   Simon Glass   dm: ide: Remove t...
96
  		}
c609719b8   wdenk   Initial revision
97

ed73508de   Simon Glass   dm: ide: Remove t...
98
99
100
  		return CMD_RET_USAGE;
  	default:
  		/* at least 4 args */
c609719b8   wdenk   Initial revision
101

ed73508de   Simon Glass   dm: ide: Remove t...
102
103
104
  		if (strcmp(argv[1], "read") == 0) {
  			ulong addr = simple_strtoul(argv[2], NULL, 16);
  			ulong cnt = simple_strtoul(argv[4], NULL, 16);
ed73508de   Simon Glass   dm: ide: Remove t...
105
  			ulong n;
c609719b8   wdenk   Initial revision
106

ed73508de   Simon Glass   dm: ide: Remove t...
107
108
  #ifdef CONFIG_SYS_64BIT_LBA
  			lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
c609719b8   wdenk   Initial revision
109

ed73508de   Simon Glass   dm: ide: Remove t...
110
111
112
113
114
  			printf("
  IDE read: device %d block # %lld, count %ld...",
  			       curr_device, blk, cnt);
  #else
  			lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
c609719b8   wdenk   Initial revision
115

ed73508de   Simon Glass   dm: ide: Remove t...
116
117
118
119
  			printf("
  IDE read: device %d block # %ld, count %ld...",
  			       curr_device, blk, cnt);
  #endif
c609719b8   wdenk   Initial revision
120

e9be1ee75   Simon Glass   dm: ide: Separate...
121
122
  			n = blk_read_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
  					    (ulong *)addr);
c609719b8   wdenk   Initial revision
123

ed73508de   Simon Glass   dm: ide: Remove t...
124
125
126
127
128
129
130
131
132
133
134
  			printf("%ld blocks read: %s
  ",
  			       n, (n == cnt) ? "OK" : "ERROR");
  			if (n == cnt)
  				return 0;
  			else
  				return 1;
  		} else if (strcmp(argv[1], "write") == 0) {
  			ulong addr = simple_strtoul(argv[2], NULL, 16);
  			ulong cnt = simple_strtoul(argv[4], NULL, 16);
  			ulong n;
c609719b8   wdenk   Initial revision
135

6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
136
  #ifdef CONFIG_SYS_64BIT_LBA
ed73508de   Simon Glass   dm: ide: Remove t...
137
138
139
140
141
  			lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
  
  			printf("
  IDE write: device %d block # %lld, count %ld...",
  			       curr_device, blk, cnt);
413bf5862   Guennadi Liakhovetski   IDE: fix compiler...
142
  #else
ed73508de   Simon Glass   dm: ide: Remove t...
143
144
145
146
147
  			lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
  
  			printf("
  IDE write: device %d block # %ld, count %ld...",
  			       curr_device, blk, cnt);
413bf5862   Guennadi Liakhovetski   IDE: fix compiler...
148
  #endif
e9be1ee75   Simon Glass   dm: ide: Separate...
149
150
  			n = blk_write_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
  					     (ulong *)addr);
ed73508de   Simon Glass   dm: ide: Remove t...
151
152
153
154
155
156
157
158
159
160
  
  			printf("%ld blocks written: %s
  ", n,
  			       n == cnt ? "OK" : "ERROR");
  			if (n == cnt)
  				return 0;
  			else
  				return 1;
  		} else {
  			return CMD_RET_USAGE;
c40b29568   wdenk   * Patch by Rune T...
161
  		}
c40b29568   wdenk   * Patch by Rune T...
162

ed73508de   Simon Glass   dm: ide: Remove t...
163
164
165
  		return rcode;
  	}
  }
c40b29568   wdenk   * Patch by Rune T...
166

ed73508de   Simon Glass   dm: ide: Remove t...
167
168
169
170
  int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  {
  	return common_diskboot(cmdtp, "ide", argc, argv);
  }
c609719b8   wdenk   Initial revision
171

34c202c7e   Wolfgang Denk   common/cmd_ide.c:...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  U_BOOT_CMD(ide, 5, 1, do_ide,
  	   "IDE sub-system",
  	   "reset - reset IDE controller
  "
  	   "ide info  - show available IDE devices
  "
  	   "ide device [dev] - show or set current device
  "
  	   "ide part [dev] - print partition table of one or all IDE devices
  "
  	   "ide read  addr blk# cnt
  "
  	   "ide write addr blk# cnt - read/write `cnt'"
  	   " blocks starting at block `blk#'
  "
  	   "    to/from memory address `addr'");
  
  U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
  	   "boot from IDE device", "loadAddr dev:part");