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