OMAP3: X-Loader: Make MMC register macros volatile
[x-load.git] / disk / part.c
bloba367f13a79deb2f480c7408c4d6b2ca1cb5f1b9e
1 /*
2 * (C) Copyright 2001
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
6 * project.
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.
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.
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
24 #include <common.h>
25 #include <command.h>
26 #include <ide.h>
27 #include <part.h>
29 #undef PART_DEBUG
31 #ifdef PART_DEBUG
32 #define PRINTF(fmt,args...) printf (fmt ,##args)
33 #else
34 #define PRINTF(fmt,args...)
35 #endif
37 #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || \
38 (CONFIG_COMMANDS & CFG_CMD_SCSI) || \
39 (CONFIG_COMMANDS & CFG_CMD_USB) || \
40 defined(CONFIG_MMC) || \
41 defined(CONFIG_SYSTEMACE) )
43 /* ------------------------------------------------------------------------- */
45 * reports device info to the user
47 void dev_print (block_dev_desc_t *dev_desc)
49 #ifdef CONFIG_LBA48
50 uint64_t lba512; /* number of blocks if 512bytes block size */
51 #else
52 lbaint_t lba512;
53 #endif
55 if (dev_desc->type==DEV_TYPE_UNKNOWN) {
56 return;
58 if (dev_desc->if_type==IF_TYPE_SCSI) {
59 printf ("(%d:%d) ", dev_desc->target,dev_desc->lun);
61 if (dev_desc->if_type==IF_TYPE_IDE) {
62 printf ("Model: %s Firm: %s Ser#: %s\n",
63 dev_desc->vendor,
64 dev_desc->revision,
65 dev_desc->product);
66 } else {
67 printf ("Vendor: %s Prod.: %s Rev: %s\n",
68 dev_desc->vendor,
69 dev_desc->product,
70 dev_desc->revision);
72 printf (" Type: ");
73 switch (dev_desc->type & 0x1F) {
74 case DEV_TYPE_HARDDISK: printf ("Hard Disk");
75 break;
76 case DEV_TYPE_CDROM: printf ("CD ROM");
77 break;
78 case DEV_TYPE_OPDISK: printf ("Optical Device");
79 break;
80 case DEV_TYPE_TAPE: printf ("Tape");
81 break;
82 default: printf ("# %02X #", dev_desc->type & 0x1F);
83 break;
85 if ((dev_desc->lba * dev_desc->blksz)>0L) {
86 ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
87 lbaint_t lba;
89 lba = dev_desc->lba;
91 lba512 = (lba * (dev_desc->blksz/512));
92 mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */
93 /* round to 1 digit */
94 mb_quot = mb / 10;
95 mb_rem = mb - (10 * mb_quot);
97 gb = mb / 1024;
98 gb_quot = gb / 10;
99 gb_rem = gb - (10 * gb_quot);
100 #ifdef CONFIG_LBA48
101 if (dev_desc->lba48)
102 printf (" Supports 48-bit addressing\n");
103 #endif
104 #if defined(CFG_64BIT_LBA) && defined(CFG_64BIT_VSPRINTF)
105 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%qd x %ld)\n",
106 mb_quot, mb_rem,
107 gb_quot, gb_rem,
108 lba,
109 dev_desc->blksz);
110 #else
111 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n",
112 mb_quot, mb_rem,
113 gb_quot, gb_rem,
114 (ulong)lba,
115 dev_desc->blksz);
116 #endif
117 } else {
118 printf (" Capacity: not available\n");
121 #endif /* CFG_CMD_IDE || CFG_CMD_SCSI || CFG_CMD_USB || CONFIG_MMC */
123 #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || \
124 (CONFIG_COMMANDS & CFG_CMD_SCSI) || \
125 (CONFIG_COMMANDS & CFG_CMD_USB) || \
126 (CONFIG_COMMANDS & CFG_CMD_MMC) || \
127 defined(CONFIG_SYSTEMACE) )
129 #if defined(CONFIG_MAC_PARTITION) || \
130 defined(CONFIG_DOS_PARTITION) || \
131 defined(CONFIG_ISO_PARTITION) || \
132 defined(CONFIG_AMIGA_PARTITION)
134 void init_part (block_dev_desc_t * dev_desc)
136 #ifdef CONFIG_ISO_PARTITION
137 if (test_part_iso(dev_desc) == 0) {
138 dev_desc->part_type = PART_TYPE_ISO;
139 return;
141 #endif
143 #ifdef CONFIG_MAC_PARTITION
144 if (test_part_mac(dev_desc) == 0) {
145 dev_desc->part_type = PART_TYPE_MAC;
146 return;
148 #endif
150 #ifdef CONFIG_DOS_PARTITION
151 if (test_part_dos(dev_desc) == 0) {
152 dev_desc->part_type = PART_TYPE_DOS;
153 return;
155 #endif
157 #ifdef CONFIG_AMIGA_PARTITION
158 if (test_part_amiga(dev_desc) == 0) {
159 dev_desc->part_type = PART_TYPE_AMIGA;
160 return;
162 #endif
166 int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
168 switch (dev_desc->part_type) {
169 #ifdef CONFIG_MAC_PARTITION
170 case PART_TYPE_MAC:
171 if (get_partition_info_mac(dev_desc,part,info) == 0) {
172 PRINTF ("## Valid MAC partition found ##\n");
173 return (0);
175 break;
176 #endif
178 #ifdef CONFIG_DOS_PARTITION
179 case PART_TYPE_DOS:
180 if (get_partition_info_dos(dev_desc,part,info) == 0) {
181 PRINTF ("## Valid DOS partition found ##\n");
182 return (0);
184 break;
185 #endif
187 #ifdef CONFIG_ISO_PARTITION
188 case PART_TYPE_ISO:
189 if (get_partition_info_iso(dev_desc,part,info) == 0) {
190 PRINTF ("## Valid ISO boot partition found ##\n");
191 return (0);
193 break;
194 #endif
196 #ifdef CONFIG_AMIGA_PARTITION
197 case PART_TYPE_AMIGA:
198 if (get_partition_info_amiga(dev_desc, part, info) == 0)
200 PRINTF ("## Valid Amiga partition found ##\n");
201 return (0);
203 break;
204 #endif
205 default:
206 break;
208 return (-1);
211 static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
213 switch (dev_desc->if_type) {
214 case IF_TYPE_IDE: printf ("IDE");
215 break;
216 case IF_TYPE_SCSI: printf ("SCSI");
217 break;
218 case IF_TYPE_ATAPI: printf ("ATAPI");
219 break;
220 case IF_TYPE_USB: printf ("USB");
221 break;
222 case IF_TYPE_DOC: printf ("DOC");
223 break;
224 default: printf ("UNKNOWN");
225 break;
227 printf (" device %d -- Partition Type: %s\n\n",
228 dev_desc->dev, type);
231 void print_part (block_dev_desc_t * dev_desc)
234 switch (dev_desc->part_type) {
235 #ifdef CONFIG_MAC_PARTITION
236 case PART_TYPE_MAC:
237 PRINTF ("## Testing for valid MAC partition ##\n");
238 print_part_header ("MAC", dev_desc);
239 print_part_mac (dev_desc);
240 return;
241 #endif
242 #ifdef CONFIG_DOS_PARTITION
243 case PART_TYPE_DOS:
244 PRINTF ("## Testing for valid DOS partition ##\n");
245 print_part_header ("DOS", dev_desc);
246 print_part_dos (dev_desc);
247 return;
248 #endif
250 #ifdef CONFIG_ISO_PARTITION
251 case PART_TYPE_ISO:
252 PRINTF ("## Testing for valid ISO Boot partition ##\n");
253 print_part_header ("ISO", dev_desc);
254 print_part_iso (dev_desc);
255 return;
256 #endif
258 #ifdef CONFIG_AMIGA_PARTITION
259 case PART_TYPE_AMIGA:
260 PRINTF ("## Testing for a valid Amiga partition ##\n");
261 print_part_header ("AMIGA", dev_desc);
262 print_part_amiga (dev_desc);
263 return;
264 #endif
269 #else /* neither MAC nor DOS nor ISO partition configured */
270 # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured!
271 #endif
273 #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */