Blame view
common/cmd_sata.c
4.89 KB
c7057b529 ata: add the supp... |
1 2 3 4 5 6 7 8 9 |
/* * Copyright (C) 2000-2005, DENX Software Engineering * Wolfgang Denk <wd@denx.de> * Copyright (C) Procsys. All rights reserved. * Mushtaq Khan <mushtaq_k@procsys.com> * <mushtaqk_921@yahoo.co.in> * Copyright (C) 2008 Freescale Semiconductor, Inc. * Dave Liu <daveliu@freescale.com> * |
1a4596601 Add GPL-2.0+ SPDX... |
10 |
* SPDX-License-Identifier: GPL-2.0+ |
c7057b529 ata: add the supp... |
11 12 13 14 15 16 |
*/ #include <common.h> #include <command.h> #include <part.h> #include <sata.h> |
088f1b199 common/cmd_*.c: s... |
17 |
static int sata_curr_device = -1; |
6d0f6bcf3 rename CFG_ macro... |
18 |
block_dev_desc_t sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE]; |
c7057b529 ata: add the supp... |
19 |
|
cf7e399fb SATA: do not auto... |
20 |
int __sata_initialize(void) |
c7057b529 ata: add the supp... |
21 22 23 |
{ int rc; int i; |
6d0f6bcf3 rename CFG_ macro... |
24 |
for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) { |
c7057b529 ata: add the supp... |
25 26 27 28 29 30 31 |
memset(&sata_dev_desc[i], 0, sizeof(struct block_dev_desc)); sata_dev_desc[i].if_type = IF_TYPE_SATA; sata_dev_desc[i].dev = i; sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN; sata_dev_desc[i].type = DEV_TYPE_HARDDISK; sata_dev_desc[i].lba = 0; sata_dev_desc[i].blksz = 512; |
0472fbfd3 part/dev_desc: Ad... |
32 |
sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz); |
c7057b529 ata: add the supp... |
33 34 35 36 |
sata_dev_desc[i].block_read = sata_read; sata_dev_desc[i].block_write = sata_write; rc = init_sata(i); |
71cadda3f SATA: check for r... |
37 38 39 40 41 42 |
if (!rc) { rc = scan_sata(i); if (!rc && (sata_dev_desc[i].lba > 0) && (sata_dev_desc[i].blksz > 0)) init_part(&sata_dev_desc[i]); } |
c7057b529 ata: add the supp... |
43 |
} |
569460ebf sata: namespace c... |
44 |
sata_curr_device = 0; |
c7057b529 ata: add the supp... |
45 46 |
return rc; } |
cf7e399fb SATA: do not auto... |
47 |
int sata_initialize(void) __attribute__((weak,alias("__sata_initialize"))); |
c7057b529 ata: add the supp... |
48 |
|
df3fc5260 disk/part.c: Make... |
49 |
#ifdef CONFIG_PARTITIONS |
c7057b529 ata: add the supp... |
50 51 |
block_dev_desc_t *sata_get_dev(int dev) { |
6d0f6bcf3 rename CFG_ macro... |
52 |
return (dev < CONFIG_SYS_SATA_MAX_DEVICE) ? &sata_dev_desc[dev] : NULL; |
c7057b529 ata: add the supp... |
53 |
} |
df3fc5260 disk/part.c: Make... |
54 |
#endif |
c7057b529 ata: add the supp... |
55 |
|
088f1b199 common/cmd_*.c: s... |
56 |
static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
c7057b529 ata: add the supp... |
57 58 |
{ int rc = 0; |
cf7e399fb SATA: do not auto... |
59 60 61 62 |
if (argc == 2 && strcmp(argv[1], "init") == 0) return sata_initialize(); /* If the user has not yet run `sata init`, do it now */ |
569460ebf sata: namespace c... |
63 |
if (sata_curr_device == -1) |
cf7e399fb SATA: do not auto... |
64 65 |
if (sata_initialize()) return 1; |
c7057b529 ata: add the supp... |
66 67 68 |
switch (argc) { case 0: case 1: |
4c12eeb8b Convert cmd_usage... |
69 |
return CMD_RET_USAGE; |
c7057b529 ata: add the supp... |
70 71 72 73 74 |
case 2: if (strncmp(argv[1],"inf", 3) == 0) { int i; putc(' '); |
6d0f6bcf3 rename CFG_ macro... |
75 |
for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; ++i) { |
c7057b529 ata: add the supp... |
76 77 78 79 80 81 82 |
if (sata_dev_desc[i].type == DEV_TYPE_UNKNOWN) continue; printf ("SATA device %d: ", i); dev_print(&sata_dev_desc[i]); } return 0; } else if (strncmp(argv[1],"dev", 3) == 0) { |
569460ebf sata: namespace c... |
83 |
if ((sata_curr_device < 0) || (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE)) { |
c7057b529 ata: add the supp... |
84 85 86 87 88 |
puts(" no SATA devices available "); return 1; } |
569460ebf sata: namespace c... |
89 90 91 |
printf(" SATA device %d: ", sata_curr_device); dev_print(&sata_dev_desc[sata_curr_device]); |
c7057b529 ata: add the supp... |
92 93 94 |
return 0; } else if (strncmp(argv[1],"part",4) == 0) { int dev, ok; |
6d0f6bcf3 rename CFG_ macro... |
95 |
for (ok = 0, dev = 0; dev < CONFIG_SYS_SATA_MAX_DEVICE; ++dev) { |
c7057b529 ata: add the supp... |
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
if (sata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) { ++ok; if (dev) putc (' '); print_part(&sata_dev_desc[dev]); } } if (!ok) { puts(" no SATA devices available "); rc ++; } return rc; } |
4c12eeb8b Convert cmd_usage... |
112 |
return CMD_RET_USAGE; |
c7057b529 ata: add the supp... |
113 114 115 116 117 118 |
case 3: if (strncmp(argv[1], "dev", 3) == 0) { int dev = (int)simple_strtoul(argv[2], NULL, 10); printf(" SATA device %d: ", dev); |
6d0f6bcf3 rename CFG_ macro... |
119 |
if (dev >= CONFIG_SYS_SATA_MAX_DEVICE) { |
c7057b529 ata: add the supp... |
120 121 122 123 124 125 126 127 |
puts ("unknown device "); return 1; } dev_print(&sata_dev_desc[dev]); if (sata_dev_desc[dev].type == DEV_TYPE_UNKNOWN) return 1; |
569460ebf sata: namespace c... |
128 |
sata_curr_device = dev; |
c7057b529 ata: add the supp... |
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
puts("... is now current device "); return 0; } else if (strncmp(argv[1], "part", 4) == 0) { int dev = (int)simple_strtoul(argv[2], NULL, 10); if (sata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) { print_part(&sata_dev_desc[dev]); } else { printf(" SATA device %d not available ", dev); rc = 1; } return rc; } |
4c12eeb8b Convert cmd_usage... |
147 |
return CMD_RET_USAGE; |
c7057b529 ata: add the supp... |
148 149 150 151 152 153 154 155 156 157 |
default: /* at least 4 args */ if (strcmp(argv[1], "read") == 0) { ulong addr = simple_strtoul(argv[2], NULL, 16); ulong cnt = simple_strtoul(argv[4], NULL, 16); ulong n; lbaint_t blk = simple_strtoul(argv[3], NULL, 16); printf(" SATA read: device %d block # %ld, count %ld ... ", |
569460ebf sata: namespace c... |
158 |
sata_curr_device, blk, cnt); |
c7057b529 ata: add the supp... |
159 |
|
569460ebf sata: namespace c... |
160 |
n = sata_read(sata_curr_device, blk, cnt, (u32 *)addr); |
c7057b529 ata: add the supp... |
161 162 |
/* flush cache after read */ |
569460ebf sata: namespace c... |
163 |
flush_cache(addr, cnt * sata_dev_desc[sata_curr_device].blksz); |
c7057b529 ata: add the supp... |
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
printf("%ld blocks read: %s ", n, (n==cnt) ? "OK" : "ERROR"); return (n == cnt) ? 0 : 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; lbaint_t blk = simple_strtoul(argv[3], NULL, 16); printf(" SATA write: device %d block # %ld, count %ld ... ", |
569460ebf sata: namespace c... |
178 |
sata_curr_device, blk, cnt); |
c7057b529 ata: add the supp... |
179 |
|
569460ebf sata: namespace c... |
180 |
n = sata_write(sata_curr_device, blk, cnt, (u32 *)addr); |
c7057b529 ata: add the supp... |
181 182 183 184 185 186 |
printf("%ld blocks written: %s ", n, (n == cnt) ? "OK" : "ERROR"); return (n == cnt) ? 0 : 1; } else { |
4c12eeb8b Convert cmd_usage... |
187 |
return CMD_RET_USAGE; |
c7057b529 ata: add the supp... |
188 189 190 191 192 193 194 195 |
} return rc; } } U_BOOT_CMD( sata, 5, 1, do_sata, |
2fb2604d5 Command usage cle... |
196 |
"SATA sub system", |
85dafbb8b common: cmd_sata:... |
197 198 |
"init - init SATA sub system " |
c7057b529 ata: add the supp... |
199 200 201 202 203 204 205 206 |
"sata info - show available SATA devices " "sata device [dev] - show or set current device " "sata part [dev] - print partition table " "sata read addr blk# cnt " |
a89c33db9 General help mess... |
207 208 |
"sata write addr blk# cnt" ); |