blob: 10fb2f95a7f371154cf3e52a72defc0384d311fa [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
Wolfgang Denk2bc10cf2011-10-29 09:41:40 +00002 * (C) Copyright 2000-2011
wdenkc6097192002-11-03 00:24:07 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
7
8/*
9 * IDE support
10 */
Albert Aribaud45027552010-08-08 05:17:06 +053011
wdenkc6097192002-11-03 00:24:07 +000012#include <common.h>
Simon Glass2ee8ada2016-02-29 15:25:52 -070013#include <blk.h>
wdenkc6097192002-11-03 00:24:07 +000014#include <config.h>
15#include <watchdog.h>
16#include <command.h>
17#include <image.h>
18#include <asm/byteorder.h>
Heiko Schocher2559e0f2007-08-28 17:39:14 +020019#include <asm/io.h>
Grant Likelyffc2dd72007-02-20 09:04:34 +010020
Heiko Schocher65d94db2017-06-07 17:33:09 +020021#if defined(CONFIG_IDE_PCMCIA)
wdenkc6097192002-11-03 00:24:07 +000022# include <pcmcia.h>
23#endif
Grant Likelyffc2dd72007-02-20 09:04:34 +010024
wdenkc6097192002-11-03 00:24:07 +000025#include <ide.h>
26#include <ata.h>
Grant Likelyffc2dd72007-02-20 09:04:34 +010027
Uri Mashiach4892d392017-01-19 10:51:45 +020028#ifdef CONFIG_LED_STATUS
wdenkc6097192002-11-03 00:24:07 +000029# include <status_led.h>
30#endif
Grant Likelyffc2dd72007-02-20 09:04:34 +010031
wdenkc6097192002-11-03 00:24:07 +000032/* Current I/O Device */
33static int curr_device = -1;
34
Simon Glass43a464a2016-05-01 11:36:00 -060035int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
36{
37 int rcode = 0;
38
39 switch (argc) {
40 case 0:
41 case 1:
42 return CMD_RET_USAGE;
43 case 2:
44 if (strncmp(argv[1], "res", 3) == 0) {
Heiko Schocher65d94db2017-06-07 17:33:09 +020045 puts("\nReset IDE: ");
Simon Glass43a464a2016-05-01 11:36:00 -060046 ide_init();
47 return 0;
48 } else if (strncmp(argv[1], "inf", 3) == 0) {
Simon Glasse11f0ef2016-05-01 11:36:10 -060049 blk_list_devices(IF_TYPE_IDE);
Simon Glass43a464a2016-05-01 11:36:00 -060050 return 0;
51
52 } else if (strncmp(argv[1], "dev", 3) == 0) {
Simon Glasse11f0ef2016-05-01 11:36:10 -060053 if (blk_print_device_num(IF_TYPE_IDE, curr_device)) {
54 printf("\nno IDE devices available\n");
55 return CMD_RET_FAILURE;
Simon Glass43a464a2016-05-01 11:36:00 -060056 }
Simon Glasse11f0ef2016-05-01 11:36:10 -060057
Simon Glass43a464a2016-05-01 11:36:00 -060058 return 0;
59 } else if (strncmp(argv[1], "part", 4) == 0) {
Simon Glasse11f0ef2016-05-01 11:36:10 -060060 if (blk_list_part(IF_TYPE_IDE))
61 printf("\nno IDE devices available\n");
62 return 1;
Simon Glass43a464a2016-05-01 11:36:00 -060063 }
64 return CMD_RET_USAGE;
65 case 3:
66 if (strncmp(argv[1], "dev", 3) == 0) {
67 int dev = (int)simple_strtoul(argv[2], NULL, 10);
wdenkc6097192002-11-03 00:24:07 +000068
Simon Glasse11f0ef2016-05-01 11:36:10 -060069 if (!blk_show_device(IF_TYPE_IDE, dev)) {
70 curr_device = dev;
71 printf("... is now current device\n");
72 } else {
73 return CMD_RET_FAILURE;
Simon Glass43a464a2016-05-01 11:36:00 -060074 }
Simon Glass43a464a2016-05-01 11:36:00 -060075 return 0;
76 } else if (strncmp(argv[1], "part", 4) == 0) {
77 int dev = (int)simple_strtoul(argv[2], NULL, 10);
wdenkc6097192002-11-03 00:24:07 +000078
Simon Glasse11f0ef2016-05-01 11:36:10 -060079 if (blk_print_part_devnum(IF_TYPE_IDE, dev)) {
80 printf("\nIDE device %d not available\n", dev);
81 return CMD_RET_FAILURE;
Simon Glass43a464a2016-05-01 11:36:00 -060082 }
Simon Glasse11f0ef2016-05-01 11:36:10 -060083 return 1;
Simon Glass43a464a2016-05-01 11:36:00 -060084 }
wdenkc6097192002-11-03 00:24:07 +000085
Simon Glass43a464a2016-05-01 11:36:00 -060086 return CMD_RET_USAGE;
87 default:
88 /* at least 4 args */
wdenkc6097192002-11-03 00:24:07 +000089
Simon Glass43a464a2016-05-01 11:36:00 -060090 if (strcmp(argv[1], "read") == 0) {
91 ulong addr = simple_strtoul(argv[2], NULL, 16);
92 ulong cnt = simple_strtoul(argv[4], NULL, 16);
Simon Glass43a464a2016-05-01 11:36:00 -060093 ulong n;
wdenkc6097192002-11-03 00:24:07 +000094
Simon Glass43a464a2016-05-01 11:36:00 -060095#ifdef CONFIG_SYS_64BIT_LBA
96 lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
wdenkc6097192002-11-03 00:24:07 +000097
Simon Glass43a464a2016-05-01 11:36:00 -060098 printf("\nIDE read: device %d block # %lld, count %ld...",
99 curr_device, blk, cnt);
100#else
101 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
wdenkc6097192002-11-03 00:24:07 +0000102
Simon Glass43a464a2016-05-01 11:36:00 -0600103 printf("\nIDE read: device %d block # %ld, count %ld...",
104 curr_device, blk, cnt);
105#endif
wdenkc6097192002-11-03 00:24:07 +0000106
Simon Glasse11f0ef2016-05-01 11:36:10 -0600107 n = blk_read_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
108 (ulong *)addr);
wdenkc6097192002-11-03 00:24:07 +0000109
Simon Glass43a464a2016-05-01 11:36:00 -0600110 printf("%ld blocks read: %s\n",
111 n, (n == cnt) ? "OK" : "ERROR");
112 if (n == cnt)
113 return 0;
114 else
115 return 1;
116 } else if (strcmp(argv[1], "write") == 0) {
117 ulong addr = simple_strtoul(argv[2], NULL, 16);
118 ulong cnt = simple_strtoul(argv[4], NULL, 16);
119 ulong n;
wdenkc6097192002-11-03 00:24:07 +0000120
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200121#ifdef CONFIG_SYS_64BIT_LBA
Simon Glass43a464a2016-05-01 11:36:00 -0600122 lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
123
124 printf("\nIDE write: device %d block # %lld, count %ld...",
125 curr_device, blk, cnt);
Guennadi Liakhovetskib71f1ca2008-04-28 14:36:06 +0200126#else
Simon Glass43a464a2016-05-01 11:36:00 -0600127 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
128
129 printf("\nIDE write: device %d block # %ld, count %ld...",
130 curr_device, blk, cnt);
Guennadi Liakhovetskib71f1ca2008-04-28 14:36:06 +0200131#endif
Simon Glasse11f0ef2016-05-01 11:36:10 -0600132 n = blk_write_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
133 (ulong *)addr);
Simon Glass43a464a2016-05-01 11:36:00 -0600134
135 printf("%ld blocks written: %s\n", n,
136 n == cnt ? "OK" : "ERROR");
137 if (n == cnt)
138 return 0;
139 else
140 return 1;
141 } else {
142 return CMD_RET_USAGE;
wdenkf602aa02004-03-13 23:29:43 +0000143 }
wdenkf602aa02004-03-13 23:29:43 +0000144
Simon Glass43a464a2016-05-01 11:36:00 -0600145 return rcode;
146 }
147}
wdenkf602aa02004-03-13 23:29:43 +0000148
Simon Glass43a464a2016-05-01 11:36:00 -0600149int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
150{
151 return common_diskboot(cmdtp, "ide", argc, argv);
152}
wdenkc6097192002-11-03 00:24:07 +0000153
Wolfgang Denk2bc10cf2011-10-29 09:41:40 +0000154U_BOOT_CMD(ide, 5, 1, do_ide,
155 "IDE sub-system",
156 "reset - reset IDE controller\n"
157 "ide info - show available IDE devices\n"
158 "ide device [dev] - show or set current device\n"
159 "ide part [dev] - print partition table of one or all IDE devices\n"
160 "ide read addr blk# cnt\n"
161 "ide write addr blk# cnt - read/write `cnt'"
162 " blocks starting at block `blk#'\n"
163 " to/from memory address `addr'");
wdenk57b2d802003-06-27 21:31:46 +0000164
Wolfgang Denk2bc10cf2011-10-29 09:41:40 +0000165U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
166 "boot from IDE device", "loadAddr dev:part");