]>
Commit | Line | Data |
---|---|---|
affae2bf WD |
1 | /* |
2 | * (C) Copyright 2001 | |
3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
4 | * | |
5 | * See file CREDITS for list of people who contributed to this | |
6 | * project. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License as | |
10 | * published by the Free Software Foundation; either version 2 of | |
11 | * the License, or (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
21 | * MA 02111-1307 USA | |
22 | */ | |
23 | ||
24 | #include <common.h> | |
25 | #include <command.h> | |
26 | #include <ide.h> | |
27 | #include <cmd_disk.h> | |
28 | ||
29 | #undef PART_DEBUG | |
30 | ||
31 | #ifdef PART_DEBUG | |
32 | #define PRINTF(fmt,args...) printf (fmt ,##args) | |
33 | #else | |
34 | #define PRINTF(fmt,args...) | |
35 | #endif | |
36 | ||
37 | #if (CONFIG_COMMANDS & CFG_CMD_IDE) || (CONFIG_COMMANDS & CFG_CMD_SCSI) | |
38 | ||
39 | /* ------------------------------------------------------------------------- */ | |
40 | /* | |
41 | * reports device info to the user | |
42 | */ | |
43 | void dev_print (block_dev_desc_t *dev_desc) | |
44 | { | |
45 | ulong lba512; /* number of blocks if 512bytes block size */ | |
46 | ||
47 | if (dev_desc->type==DEV_TYPE_UNKNOWN) { | |
48 | puts ("not available\n"); | |
49 | return; | |
50 | } | |
51 | if (dev_desc->if_type==IF_TYPE_SCSI) { | |
52 | printf ("(%d:%d) ", dev_desc->target,dev_desc->lun); | |
53 | } | |
54 | if (dev_desc->if_type==IF_TYPE_IDE) { | |
55 | printf ("Model: %s Firm: %s Ser#: %s\n", | |
56 | dev_desc->vendor, | |
57 | dev_desc->revision, | |
58 | dev_desc->product); | |
59 | } else { | |
60 | printf ("Vendor: %s Prod.: %s Rev: %s\n", | |
61 | dev_desc->vendor, | |
62 | dev_desc->product, | |
63 | dev_desc->revision); | |
64 | } | |
65 | puts (" Type: "); | |
66 | if (dev_desc->removable) | |
67 | puts ("Removable "); | |
68 | switch (dev_desc->type & 0x1F) { | |
69 | case DEV_TYPE_HARDDISK: puts ("Hard Disk"); | |
70 | break; | |
71 | case DEV_TYPE_CDROM: puts ("CD ROM"); | |
72 | break; | |
73 | case DEV_TYPE_OPDISK: puts ("Optical Device"); | |
74 | break; | |
75 | case DEV_TYPE_TAPE: puts ("Tape"); | |
76 | break; | |
77 | default: printf ("# %02X #", dev_desc->type & 0x1F); | |
78 | break; | |
79 | } | |
80 | puts ("\n"); | |
81 | if ((dev_desc->lba * dev_desc->blksz)>0L) { | |
82 | ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem; | |
83 | ||
84 | lba512 = (dev_desc->lba * (dev_desc->blksz/512)); | |
85 | ||
86 | mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */ | |
87 | /* round to 1 digit */ | |
88 | mb_quot = mb / 10; | |
89 | mb_rem = mb - (10 * mb_quot); | |
90 | ||
91 | gb = mb / 1024; | |
92 | gb_quot = gb / 10; | |
93 | gb_rem = gb - (10 * gb_quot); | |
94 | ||
95 | printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n", | |
96 | mb_quot, mb_rem, | |
97 | gb_quot, gb_rem, | |
98 | dev_desc->lba, | |
99 | dev_desc->blksz); | |
100 | } else { | |
101 | puts (" Capacity: not available\n"); | |
102 | } | |
103 | } | |
104 | ||
105 | ||
affae2bf WD |
106 | #if defined(CONFIG_MAC_PARTITION) || \ |
107 | defined(CONFIG_DOS_PARTITION) || \ | |
c7de829c | 108 | defined(CONFIG_ISO_PARTITION) || \ |
8bde7f77 | 109 | defined(CONFIG_AMIGA_PARTITION) |
affae2bf WD |
110 | |
111 | void init_part (block_dev_desc_t * dev_desc) | |
112 | { | |
113 | #ifdef CONFIG_ISO_PARTITION | |
114 | if (test_part_iso(dev_desc) == 0) { | |
115 | dev_desc->part_type = PART_TYPE_ISO; | |
116 | return; | |
117 | } | |
118 | #endif | |
119 | ||
120 | #ifdef CONFIG_MAC_PARTITION | |
121 | if (test_part_mac(dev_desc) == 0) { | |
122 | dev_desc->part_type = PART_TYPE_MAC; | |
123 | return; | |
124 | } | |
125 | #endif | |
126 | ||
127 | #ifdef CONFIG_DOS_PARTITION | |
128 | if (test_part_dos(dev_desc) == 0) { | |
129 | dev_desc->part_type = PART_TYPE_DOS; | |
130 | return; | |
131 | } | |
132 | #endif | |
c7de829c WD |
133 | |
134 | #ifdef CONFIG_AMIGA_PARTITION | |
135 | if (test_part_amiga(dev_desc) == 0) { | |
136 | dev_desc->part_type = PART_TYPE_AMIGA; | |
137 | return; | |
138 | } | |
139 | #endif | |
affae2bf WD |
140 | } |
141 | ||
142 | ||
143 | int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info) | |
144 | { | |
145 | switch (dev_desc->part_type) { | |
146 | #ifdef CONFIG_MAC_PARTITION | |
147 | case PART_TYPE_MAC: | |
148 | if (get_partition_info_mac(dev_desc,part,info) == 0) { | |
149 | PRINTF ("## Valid MAC partition found ##\n"); | |
150 | return (0); | |
151 | } | |
152 | break; | |
153 | #endif | |
154 | ||
155 | #ifdef CONFIG_DOS_PARTITION | |
156 | case PART_TYPE_DOS: | |
157 | if (get_partition_info_dos(dev_desc,part,info) == 0) { | |
158 | PRINTF ("## Valid DOS partition found ##\n"); | |
159 | return (0); | |
160 | } | |
161 | break; | |
162 | #endif | |
163 | ||
164 | #ifdef CONFIG_ISO_PARTITION | |
165 | case PART_TYPE_ISO: | |
166 | if (get_partition_info_iso(dev_desc,part,info) == 0) { | |
167 | PRINTF ("## Valid ISO boot partition found ##\n"); | |
168 | return (0); | |
169 | } | |
170 | break; | |
171 | #endif | |
c7de829c WD |
172 | |
173 | #ifdef CONFIG_AMIGA_PARTITION | |
174 | case PART_TYPE_AMIGA: | |
175 | if (get_partition_info_amiga(dev_desc, part, info) == 0) | |
176 | { | |
177 | PRINTF ("## Valid Amiga partition found ##\n"); | |
178 | return (0); | |
179 | } | |
180 | break; | |
181 | #endif | |
affae2bf WD |
182 | default: |
183 | break; | |
184 | } | |
185 | return (-1); | |
186 | } | |
187 | ||
188 | static void print_part_header (const char *type, block_dev_desc_t * dev_desc) | |
189 | { | |
190 | puts ("\nPartition Map for "); | |
191 | switch (dev_desc->if_type) { | |
192 | case IF_TYPE_IDE: puts ("IDE"); | |
193 | break; | |
194 | case IF_TYPE_SCSI: puts ("SCSI"); | |
195 | break; | |
196 | case IF_TYPE_ATAPI: puts ("ATAPI"); | |
197 | break; | |
198 | case IF_TYPE_USB: puts ("USB"); | |
199 | break; | |
200 | case IF_TYPE_DOC: puts ("DOC"); | |
201 | break; | |
202 | default: puts ("UNKNOWN"); | |
203 | break; | |
204 | } | |
205 | printf (" device %d -- Partition Type: %s\n\n", | |
206 | dev_desc->dev, type); | |
207 | } | |
208 | ||
209 | void print_part (block_dev_desc_t * dev_desc) | |
210 | { | |
211 | ||
212 | switch (dev_desc->part_type) { | |
213 | #ifdef CONFIG_MAC_PARTITION | |
214 | case PART_TYPE_MAC: | |
215 | PRINTF ("## Testing for valid MAC partition ##\n"); | |
216 | print_part_header ("MAC", dev_desc); | |
217 | print_part_mac (dev_desc); | |
218 | return; | |
219 | #endif | |
220 | #ifdef CONFIG_DOS_PARTITION | |
221 | case PART_TYPE_DOS: | |
222 | PRINTF ("## Testing for valid DOS partition ##\n"); | |
223 | print_part_header ("DOS", dev_desc); | |
224 | print_part_dos (dev_desc); | |
225 | return; | |
226 | #endif | |
227 | ||
228 | #ifdef CONFIG_ISO_PARTITION | |
229 | case PART_TYPE_ISO: | |
230 | PRINTF ("## Testing for valid ISO Boot partition ##\n"); | |
231 | print_part_header ("ISO", dev_desc); | |
232 | print_part_iso (dev_desc); | |
233 | return; | |
234 | #endif | |
c7de829c WD |
235 | |
236 | #ifdef CONFIG_AMIGA_PARTITION | |
237 | case PART_TYPE_AMIGA: | |
238 | PRINTF ("## Testing for a valid Amiga partition ##\n"); | |
239 | print_part_header ("AMIGA", dev_desc); | |
240 | print_part_amiga (dev_desc); | |
241 | return; | |
242 | #endif | |
affae2bf WD |
243 | } |
244 | puts ("## Unknown partition table\n"); | |
245 | } | |
246 | ||
247 | ||
248 | #else /* neither MAC nor DOS nor ISO partition configured */ | |
249 | # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured! | |
250 | #endif | |
251 | ||
252 | #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */ |