blob: 10fb2f95a7f371154cf3e52a72defc0384d311fa [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
Wolfgang Denk34c202c2011-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 Denk1a459662013-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 Aribaud113bfe42010-08-08 05:17:06 +053011
wdenkc6097192002-11-03 00:24:07 +000012#include <common.h>
Simon Glass2a981dc2016-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 Schocherf98984c2007-08-28 17:39:14 +020019#include <asm/io.h>
Grant Likely735dd972007-02-20 09:04:34 +010020
Heiko Schocher5b8e76c2017-06-07 17:33:09 +020021#if defined(CONFIG_IDE_PCMCIA)
wdenkc6097192002-11-03 00:24:07 +000022# include <pcmcia.h>
23#endif
Grant Likely735dd972007-02-20 09:04:34 +010024
wdenkc6097192002-11-03 00:24:07 +000025#include <ide.h>
26#include <ata.h>
Grant Likely735dd972007-02-20 09:04:34 +010027
Uri Mashiach2d8d1902017-01-19 10:51:45 +020028#ifdef CONFIG_LED_STATUS
wdenkc6097192002-11-03 00:24:07 +000029# include <status_led.h>
30#endif
Grant Likely735dd972007-02-20 09:04:34 +010031
wdenkc6097192002-11-03 00:24:07 +000032/* Current I/O Device */
33static int curr_device = -1;
34
Wolfgang Denk34c202c2011-10-29 09:41:40 +000035int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
wdenkc6097192002-11-03 00:24:07 +000036{
Wolfgang Denk34c202c2011-10-29 09:41:40 +000037 int rcode = 0;
wdenkc6097192002-11-03 00:24:07 +000038
Wolfgang Denk34c202c2011-10-29 09:41:40 +000039 switch (argc) {
40 case 0:
41 case 1:
Simon Glass4c12eeb2011-12-10 08:44:01 +000042 return CMD_RET_USAGE;
Wolfgang Denk34c202c2011-10-29 09:41:40 +000043 case 2:
44 if (strncmp(argv[1], "res", 3) == 0) {
Heiko Schocher5b8e76c2017-06-07 17:33:09 +020045 puts("\nReset IDE: ");
Wolfgang Denk34c202c2011-10-29 09:41:40 +000046 ide_init();
47 return 0;
48 } else if (strncmp(argv[1], "inf", 3) == 0) {
Simon Glasse9be1ee2016-05-01 11:36:10 -060049 blk_list_devices(IF_TYPE_IDE);
Wolfgang Denk34c202c2011-10-29 09:41:40 +000050 return 0;
51
52 } else if (strncmp(argv[1], "dev", 3) == 0) {
Simon Glasse9be1ee2016-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;
Wolfgang Denk34c202c2011-10-29 09:41:40 +000056 }
Simon Glasse9be1ee2016-05-01 11:36:10 -060057
Wolfgang Denk34c202c2011-10-29 09:41:40 +000058 return 0;
59 } else if (strncmp(argv[1], "part", 4) == 0) {
Simon Glasse9be1ee2016-05-01 11:36:10 -060060 if (blk_list_part(IF_TYPE_IDE))
61 printf("\nno IDE devices available\n");
62 return 1;
Wolfgang Denk34c202c2011-10-29 09:41:40 +000063 }
Simon Glass4c12eeb2011-12-10 08:44:01 +000064 return CMD_RET_USAGE;
Wolfgang Denk34c202c2011-10-29 09:41:40 +000065 case 3:
66 if (strncmp(argv[1], "dev", 3) == 0) {
Simon Glass53dbcdd2016-05-01 11:35:59 -060067 int dev = (int)simple_strtoul(argv[2], NULL, 10);
Wolfgang Denk34c202c2011-10-29 09:41:40 +000068
Simon Glasse9be1ee2016-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;
Wolfgang Denk34c202c2011-10-29 09:41:40 +000074 }
Wolfgang Denk34c202c2011-10-29 09:41:40 +000075 return 0;
76 } else if (strncmp(argv[1], "part", 4) == 0) {
Simon Glass53dbcdd2016-05-01 11:35:59 -060077 int dev = (int)simple_strtoul(argv[2], NULL, 10);
Wolfgang Denk34c202c2011-10-29 09:41:40 +000078
Simon Glasse9be1ee2016-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;
Wolfgang Denk34c202c2011-10-29 09:41:40 +000082 }
Simon Glasse9be1ee2016-05-01 11:36:10 -060083 return 1;
Wolfgang Denk34c202c2011-10-29 09:41:40 +000084 }
85
Simon Glass4c12eeb2011-12-10 08:44:01 +000086 return CMD_RET_USAGE;
Wolfgang Denk34c202c2011-10-29 09:41:40 +000087 default:
88 /* at least 4 args */
89
90 if (strcmp(argv[1], "read") == 0) {
91 ulong addr = simple_strtoul(argv[2], NULL, 16);
92 ulong cnt = simple_strtoul(argv[4], NULL, 16);
93 ulong n;
94
95#ifdef CONFIG_SYS_64BIT_LBA
96 lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
97
Simon Glass53dbcdd2016-05-01 11:35:59 -060098 printf("\nIDE read: device %d block # %lld, count %ld...",
99 curr_device, blk, cnt);
Wolfgang Denk34c202c2011-10-29 09:41:40 +0000100#else
101 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
102
Simon Glass53dbcdd2016-05-01 11:35:59 -0600103 printf("\nIDE read: device %d block # %ld, count %ld...",
104 curr_device, blk, cnt);
Wolfgang Denk34c202c2011-10-29 09:41:40 +0000105#endif
106
Simon Glasse9be1ee2016-05-01 11:36:10 -0600107 n = blk_read_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
108 (ulong *)addr);
Wolfgang Denk34c202c2011-10-29 09:41:40 +0000109
110 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;
120
121#ifdef CONFIG_SYS_64BIT_LBA
122 lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
123
Simon Glass53dbcdd2016-05-01 11:35:59 -0600124 printf("\nIDE write: device %d block # %lld, count %ld...",
125 curr_device, blk, cnt);
Wolfgang Denk34c202c2011-10-29 09:41:40 +0000126#else
127 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
128
Simon Glass53dbcdd2016-05-01 11:35:59 -0600129 printf("\nIDE write: device %d block # %ld, count %ld...",
130 curr_device, blk, cnt);
Wolfgang Denk34c202c2011-10-29 09:41:40 +0000131#endif
Simon Glasse9be1ee2016-05-01 11:36:10 -0600132 n = blk_write_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
133 (ulong *)addr);
Wolfgang Denk34c202c2011-10-29 09:41:40 +0000134
Simon Glassed735082016-05-01 11:36:00 -0600135 printf("%ld blocks written: %s\n", n,
136 n == cnt ? "OK" : "ERROR");
Wolfgang Denk34c202c2011-10-29 09:41:40 +0000137 if (n == cnt)
138 return 0;
139 else
140 return 1;
141 } else {
Simon Glass4c12eeb2011-12-10 08:44:01 +0000142 return CMD_RET_USAGE;
Wolfgang Denk34c202c2011-10-29 09:41:40 +0000143 }
144
145 return rcode;
146 }
wdenkc6097192002-11-03 00:24:07 +0000147}
148
Wolfgang Denk34c202c2011-10-29 09:41:40 +0000149int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
wdenkc6097192002-11-03 00:24:07 +0000150{
Rob Herring7405a132012-09-21 04:02:30 +0000151 return common_diskboot(cmdtp, "ide", argc, argv);
wdenkc6097192002-11-03 00:24:07 +0000152}
153
Wolfgang Denk34c202c2011-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'");
wdenk8bde7f72003-06-27 21:31:46 +0000164
Wolfgang Denk34c202c2011-10-29 09:41:40 +0000165U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
166 "boot from IDE device", "loadAddr dev:part");