2 * (C) Copyright 2000-2011
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
18 #include <asm/byteorder.h>
21 #if defined(CONFIG_IDE_8xx_DIRECT) || defined(CONFIG_IDE_PCMCIA)
28 #ifdef CONFIG_LED_STATUS
29 # include <status_led.h>
32 /* Current I/O Device */
33 static int curr_device = -1;
35 int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
44 if (strncmp(argv[1], "res", 3) == 0) {
46 #ifdef CONFIG_IDE_8xx_DIRECT
47 " on PCMCIA " PCMCIA_SLOT_MSG
53 } else if (strncmp(argv[1], "inf", 3) == 0) {
54 blk_list_devices(IF_TYPE_IDE);
57 } else if (strncmp(argv[1], "dev", 3) == 0) {
58 if (blk_print_device_num(IF_TYPE_IDE, curr_device)) {
59 printf("\nno IDE devices available\n");
60 return CMD_RET_FAILURE;
64 } else if (strncmp(argv[1], "part", 4) == 0) {
65 if (blk_list_part(IF_TYPE_IDE))
66 printf("\nno IDE devices available\n");
71 if (strncmp(argv[1], "dev", 3) == 0) {
72 int dev = (int)simple_strtoul(argv[2], NULL, 10);
74 if (!blk_show_device(IF_TYPE_IDE, dev)) {
76 printf("... is now current device\n");
78 return CMD_RET_FAILURE;
81 } else if (strncmp(argv[1], "part", 4) == 0) {
82 int dev = (int)simple_strtoul(argv[2], NULL, 10);
84 if (blk_print_part_devnum(IF_TYPE_IDE, dev)) {
85 printf("\nIDE device %d not available\n", dev);
86 return CMD_RET_FAILURE;
95 if (strcmp(argv[1], "read") == 0) {
96 ulong addr = simple_strtoul(argv[2], NULL, 16);
97 ulong cnt = simple_strtoul(argv[4], NULL, 16);
100 #ifdef CONFIG_SYS_64BIT_LBA
101 lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
103 printf("\nIDE read: device %d block # %lld, count %ld...",
104 curr_device, blk, cnt);
106 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
108 printf("\nIDE read: device %d block # %ld, count %ld...",
109 curr_device, blk, cnt);
112 n = blk_read_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
115 printf("%ld blocks read: %s\n",
116 n, (n == cnt) ? "OK" : "ERROR");
121 } else if (strcmp(argv[1], "write") == 0) {
122 ulong addr = simple_strtoul(argv[2], NULL, 16);
123 ulong cnt = simple_strtoul(argv[4], NULL, 16);
126 #ifdef CONFIG_SYS_64BIT_LBA
127 lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
129 printf("\nIDE write: device %d block # %lld, count %ld...",
130 curr_device, blk, cnt);
132 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
134 printf("\nIDE write: device %d block # %ld, count %ld...",
135 curr_device, blk, cnt);
137 n = blk_write_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
140 printf("%ld blocks written: %s\n", n,
141 n == cnt ? "OK" : "ERROR");
147 return CMD_RET_USAGE;
154 int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
156 return common_diskboot(cmdtp, "ide", argc, argv);
159 U_BOOT_CMD(ide, 5, 1, do_ide,
161 "reset - reset IDE controller\n"
162 "ide info - show available IDE devices\n"
163 "ide device [dev] - show or set current device\n"
164 "ide part [dev] - print partition table of one or all IDE devices\n"
165 "ide read addr blk# cnt\n"
166 "ide write addr blk# cnt - read/write `cnt'"
167 " blocks starting at block `blk#'\n"
168 " to/from memory address `addr'");
170 U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
171 "boot from IDE device", "loadAddr dev:part");