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_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) {
45 puts("\nReset IDE: ");
48 } else if (strncmp(argv[1], "inf", 3) == 0) {
49 blk_list_devices(IF_TYPE_IDE);
52 } else if (strncmp(argv[1], "dev", 3) == 0) {
53 if (blk_print_device_num(IF_TYPE_IDE, curr_device)) {
54 printf("\nno IDE devices available\n");
55 return CMD_RET_FAILURE;
59 } else if (strncmp(argv[1], "part", 4) == 0) {
60 if (blk_list_part(IF_TYPE_IDE))
61 printf("\nno IDE devices available\n");
66 if (strncmp(argv[1], "dev", 3) == 0) {
67 int dev = (int)simple_strtoul(argv[2], NULL, 10);
69 if (!blk_show_device(IF_TYPE_IDE, dev)) {
71 printf("... is now current device\n");
73 return CMD_RET_FAILURE;
76 } else if (strncmp(argv[1], "part", 4) == 0) {
77 int dev = (int)simple_strtoul(argv[2], NULL, 10);
79 if (blk_print_part_devnum(IF_TYPE_IDE, dev)) {
80 printf("\nIDE device %d not available\n", dev);
81 return CMD_RET_FAILURE;
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);
95 #ifdef CONFIG_SYS_64BIT_LBA
96 lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
98 printf("\nIDE read: device %d block # %lld, count %ld...",
99 curr_device, blk, cnt);
101 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
103 printf("\nIDE read: device %d block # %ld, count %ld...",
104 curr_device, blk, cnt);
107 n = blk_read_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
110 printf("%ld blocks read: %s\n",
111 n, (n == cnt) ? "OK" : "ERROR");
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);
121 #ifdef CONFIG_SYS_64BIT_LBA
122 lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
124 printf("\nIDE write: device %d block # %lld, count %ld...",
125 curr_device, blk, cnt);
127 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
129 printf("\nIDE write: device %d block # %ld, count %ld...",
130 curr_device, blk, cnt);
132 n = blk_write_devnum(IF_TYPE_IDE, curr_device, blk, cnt,
135 printf("%ld blocks written: %s\n", n,
136 n == cnt ? "OK" : "ERROR");
142 return CMD_RET_USAGE;
149 int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
151 return common_diskboot(cmdtp, "ide", argc, argv);
154 U_BOOT_CMD(ide, 5, 1, do_ide,
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'");
165 U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
166 "boot from IDE device", "loadAddr dev:part");