3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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,
29 #include "part_uefi.h"
34 #define PRINTF(fmt,args...) printf (fmt ,##args)
36 #define PRINTF(fmt,args...)
39 #if (defined(CONFIG_CMD_IDE) || \
40 defined(CONFIG_CMD_MG_DISK) || \
41 defined(CONFIG_CMD_SATA) || \
42 defined(CONFIG_CMD_SCSI) || \
43 defined(CONFIG_CMD_USB) || \
44 defined(CONFIG_MMC) || \
45 defined(CONFIG_SYSTEMACE) )
49 block_dev_desc_t* (*get_dev)(int dev);
52 static const struct block_drvr block_drvr[] = {
53 #if defined(CONFIG_CMD_IDE)
54 { .name = "ide", .get_dev = ide_get_dev, },
56 #if defined(CONFIG_CMD_SATA)
57 {.name = "sata", .get_dev = sata_get_dev, },
59 #if defined(CONFIG_CMD_SCSI)
60 { .name = "scsi", .get_dev = scsi_get_dev, },
62 #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
63 { .name = "usb", .get_dev = usb_stor_get_dev, },
65 #if defined(CONFIG_MMC)
66 { .name = "mmc", .get_dev = mmc_get_dev, },
68 #if defined(CONFIG_SYSTEMACE)
69 { .name = "ace", .get_dev = systemace_get_dev, },
71 #if defined(CONFIG_CMD_MG_DISK)
72 { .name = "mgd", .get_dev = mg_disk_get_dev, },
77 DECLARE_GLOBAL_DATA_PTR;
79 block_dev_desc_t *get_dev(char* ifname, int dev)
81 const struct block_drvr *drvr = block_drvr;
82 block_dev_desc_t* (*reloc_get_dev)(int dev);
86 #ifdef CONFIG_NEEDS_MANUAL_RELOC
87 name += gd->reloc_off;
91 reloc_get_dev = drvr->get_dev;
92 #ifdef CONFIG_NEEDS_MANUAL_RELOC
93 name += gd->reloc_off;
94 reloc_get_dev += gd->reloc_off;
96 if (strncmp(ifname, name, strlen(name)) == 0)
97 return reloc_get_dev(dev);
103 block_dev_desc_t *get_dev(char* ifname, int dev)
109 #if (defined(CONFIG_CMD_IDE) || \
110 defined(CONFIG_CMD_MG_DISK) || \
111 defined(CONFIG_CMD_SATA) || \
112 defined(CONFIG_CMD_SCSI) || \
113 defined(CONFIG_CMD_USB) || \
114 defined(CONFIG_MMC) || \
115 defined(CONFIG_SYSTEMACE) )
117 /* ------------------------------------------------------------------------- */
119 * reports device info to the user
123 typedef uint64_t lba512_t;
125 typedef lbaint_t lba512_t;
129 * Overflowless variant of (block_count * mul_by / div_by)
130 * when div_by > mul_by
132 static lba512_t lba512_muldiv (lba512_t block_count, lba512_t mul_by, lba512_t div_by)
134 lba512_t bc_quot, bc_rem;
136 /* x * m / d == x / d * m + (x % d) * m / d */
137 bc_quot = block_count / div_by;
138 bc_rem = block_count - div_by * bc_quot;
139 return bc_quot * mul_by + (bc_rem * mul_by) / div_by;
142 void dev_print (block_dev_desc_t *dev_desc)
144 lba512_t lba512; /* number of blocks if 512bytes block size */
146 if (dev_desc->type == DEV_TYPE_UNKNOWN) {
147 puts ("not available\n");
151 switch (dev_desc->if_type) {
153 printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n",
154 dev_desc->target,dev_desc->lun,
162 printf ("Model: %s Firm: %s Ser#: %s\n",
170 printf ("Vendor: %s Rev: %s Prod: %s\n",
176 puts("device type DOC\n");
178 case IF_TYPE_UNKNOWN:
179 puts("device type unknown\n");
182 printf("Unhandled device type: %i\n", dev_desc->if_type);
186 if (dev_desc->removable)
188 switch (dev_desc->type & 0x1F) {
189 case DEV_TYPE_HARDDISK:
195 case DEV_TYPE_OPDISK:
196 puts ("Optical Device");
202 printf ("# %02X #", dev_desc->type & 0x1F);
206 if ((dev_desc->lba * dev_desc->blksz)>0L) {
207 ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
212 lba512 = (lba * (dev_desc->blksz/512));
213 /* round to 1 digit */
214 mb = lba512_muldiv(lba512, 10, 2048); /* 2048 = (1024 * 1024) / 512 MB */
217 mb_rem = mb - (10 * mb_quot);
221 gb_rem = gb - (10 * gb_quot);
224 printf (" Supports 48-bit addressing\n");
226 #if defined(CONFIG_SYS_64BIT_LBA)
227 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%Ld x %ld)\n",
233 printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n",
240 puts (" Capacity: not available\n");
245 #if (defined(CONFIG_CMD_IDE) || \
246 defined(CONFIG_CMD_MG_DISK) || \
247 defined(CONFIG_CMD_SATA) || \
248 defined(CONFIG_CMD_SCSI) || \
249 defined(CONFIG_CMD_USB) || \
250 defined(CONFIG_MMC) || \
251 defined(CONFIG_SYSTEMACE) )
253 #if defined(CONFIG_MAC_PARTITION) || \
254 defined(CONFIG_DOS_PARTITION) || \
255 defined(CONFIG_ISO_PARTITION) || \
256 defined(CONFIG_AMIGA_PARTITION) || \
257 defined(CONFIG_EFI_PARTITION)
259 void init_part (block_dev_desc_t * dev_desc)
261 #ifdef CONFIG_ISO_PARTITION
262 if (test_part_iso(dev_desc) == 0) {
263 dev_desc->part_type = PART_TYPE_ISO;
268 #ifdef CONFIG_MAC_PARTITION
269 if (test_part_mac(dev_desc) == 0) {
270 dev_desc->part_type = PART_TYPE_MAC;
275 /* must be placed before DOS partition detection */
276 #ifdef CONFIG_EFI_PARTITION
277 if (test_part_efi(dev_desc) == 0) {
278 dev_desc->part_type = PART_TYPE_EFI;
283 #ifdef CONFIG_DOS_PARTITION
284 if (test_part_dos(dev_desc) == 0) {
285 dev_desc->part_type = PART_TYPE_DOS;
290 #ifdef CONFIG_AMIGA_PARTITION
291 if (test_part_amiga(dev_desc) == 0) {
292 dev_desc->part_type = PART_TYPE_AMIGA;
299 int get_partition_info (block_dev_desc_t *dev_desc, int part
300 , disk_partition_t *info)
302 switch (dev_desc->part_type) {
303 #ifdef CONFIG_MAC_PARTITION
305 if (get_partition_info_mac(dev_desc,part,info) == 0) {
306 PRINTF ("## Valid MAC partition found ##\n");
312 #ifdef CONFIG_DOS_PARTITION
314 if (get_partition_info_dos(dev_desc,part,info) == 0) {
315 PRINTF ("## Valid DOS partition found ##\n");
321 #ifdef CONFIG_ISO_PARTITION
323 if (get_partition_info_iso(dev_desc,part,info) == 0) {
324 PRINTF ("## Valid ISO boot partition found ##\n");
330 #ifdef CONFIG_AMIGA_PARTITION
331 case PART_TYPE_AMIGA:
332 if (get_partition_info_amiga(dev_desc, part, info) == 0)
334 PRINTF ("## Valid Amiga partition found ##\n");
340 #ifdef CONFIG_EFI_PARTITION
342 if (get_partition_info_efi(dev_desc,part,info) == 0) {
343 PRINTF ("## Valid EFI partition found ##\n");
354 int get_partition_info_with_partnum (block_dev_desc_t *dev_desc, int part
355 , disk_partition_t *info, unsigned long total,unsigned long sdidx, int sdpart, disk_partition_t *sdinfo)
357 switch (dev_desc->part_type) {
358 #ifdef CONFIG_MAC_PARTITION
360 if (get_partition_info_mac(dev_desc,part,info) == 0) {
361 PRINTF ("## Valid MAC partition found ##\n");
367 #ifdef CONFIG_DOS_PARTITION
369 if (get_partition_info_dos(dev_desc,part,info) == 0) {
370 PRINTF ("## Valid DOS partition found ##\n");
376 #ifdef CONFIG_ISO_PARTITION
378 if (get_partition_info_iso(dev_desc,part,info) == 0) {
379 PRINTF ("## Valid ISO boot partition found ##\n");
385 #ifdef CONFIG_AMIGA_PARTITION
386 case PART_TYPE_AMIGA:
387 if (get_partition_info_amiga(dev_desc, part, info) == 0)
389 PRINTF ("## Valid Amiga partition found ##\n");
395 #ifdef CONFIG_EFI_PARTITION
397 if (get_partition_info_efi_with_partnum(dev_desc,part,info, total, sdidx, sdpart, sdinfo) == 0) {
398 PRINTF ("## Valid EFI partition found ##\n");
409 int get_all_partition_info (block_dev_desc_t *dev_desc, PARTITION_CFG *info, unsigned int *total_partition_num)
411 switch(dev_desc->part_type){
412 #ifdef CONFIG_EFI_PARTITION
414 if (get_all_partition_info_efi(dev_desc,info,total_partition_num) == 0) {
415 PRINTF ("## Get All EFI partition ##\n");
426 int get_partition_info_by_name (block_dev_desc_t *dev_desc, wchar_t* partition_name,
427 disk_partition_t *info)
429 switch(dev_desc->part_type){
430 #ifdef CONFIG_EFI_PARTITION
432 if (get_partition_info_by_name_efi(dev_desc, partition_name, info)== 0) {
433 PRINTF ("## Valid EFI partition found ##\n");
444 int get_partition_num_by_name(block_dev_desc_t *dev_desc, const char *partition_name)
448 switch(dev_desc->part_type){
449 #ifdef CONFIG_EFI_PARTITION
451 ret = get_partition_num_by_name_efi(dev_desc, partition_name);
461 static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
463 puts ("\nPartition Map for ");
464 switch (dev_desc->if_type) {
490 printf (" device %d -- Partition Type: %s\n\n",
491 dev_desc->dev, type);
494 void print_part (block_dev_desc_t * dev_desc)
497 switch (dev_desc->part_type) {
498 #ifdef CONFIG_MAC_PARTITION
500 PRINTF ("## Testing for valid MAC partition ##\n");
501 print_part_header ("MAC", dev_desc);
502 print_part_mac (dev_desc);
505 #ifdef CONFIG_DOS_PARTITION
507 PRINTF ("## Testing for valid DOS partition ##\n");
508 print_part_header ("DOS", dev_desc);
509 print_part_dos (dev_desc);
513 #ifdef CONFIG_ISO_PARTITION
515 PRINTF ("## Testing for valid ISO Boot partition ##\n");
516 print_part_header ("ISO", dev_desc);
517 print_part_iso (dev_desc);
521 #ifdef CONFIG_AMIGA_PARTITION
522 case PART_TYPE_AMIGA:
523 PRINTF ("## Testing for a valid Amiga partition ##\n");
524 print_part_header ("AMIGA", dev_desc);
525 print_part_amiga (dev_desc);
529 #ifdef CONFIG_EFI_PARTITION
531 PRINTF ("## Testing for valid EFI partition ##\n");
532 print_part_header ("EFI", dev_desc);
533 print_part_efi (dev_desc);
537 puts ("## Unknown partition table\n");
541 #else /* neither MAC nor DOS nor ISO nor AMIGA nor EFI partition configured */
542 # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION
543 # error nor CONFIG_ISO_PARTITION nor CONFIG_AMIGA_PARTITION
544 # error nor CONFIG_EFI_PARTITION configured!