xref: /openbmc/u-boot/disk/part.c (revision c40b2956)
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 
36149dded2Swdenk #if ((CONFIG_COMMANDS & CFG_CMD_IDE)	|| \
37149dded2Swdenk      (CONFIG_COMMANDS & CFG_CMD_SCSI)	|| \
38c935d3bdSwdenk      (CONFIG_COMMANDS & CFG_CMD_USB)	|| \
393f85ce27Swdenk      (CONFIG_MMC) || (CONFIG_SYSTEMACE) )
40affae2bfSwdenk 
41affae2bfSwdenk /* ------------------------------------------------------------------------- */
42affae2bfSwdenk /*
43affae2bfSwdenk  * reports device info to the user
44affae2bfSwdenk  */
45affae2bfSwdenk void dev_print (block_dev_desc_t *dev_desc)
46affae2bfSwdenk {
47*c40b2956Swdenk #if CONFIG_LBA48
48*c40b2956Swdenk 	uint64_t lba512; /* number of blocks if 512bytes block size */
49*c40b2956Swdenk #else
50*c40b2956Swdenk 	lbaint_t lba512;
51*c40b2956Swdenk #endif
52affae2bfSwdenk 
53affae2bfSwdenk 	if (dev_desc->type==DEV_TYPE_UNKNOWN) {
54affae2bfSwdenk 		puts ("not available\n");
55affae2bfSwdenk 		return;
56affae2bfSwdenk 	}
57affae2bfSwdenk 	if (dev_desc->if_type==IF_TYPE_SCSI)  {
58affae2bfSwdenk 		printf ("(%d:%d) ", dev_desc->target,dev_desc->lun);
59affae2bfSwdenk 	}
60affae2bfSwdenk 	if (dev_desc->if_type==IF_TYPE_IDE) {
61affae2bfSwdenk 		printf ("Model: %s Firm: %s Ser#: %s\n",
62affae2bfSwdenk 			dev_desc->vendor,
63affae2bfSwdenk 			dev_desc->revision,
64affae2bfSwdenk 			dev_desc->product);
65affae2bfSwdenk 	} else {
66affae2bfSwdenk 		printf ("Vendor: %s Prod.: %s Rev: %s\n",
67affae2bfSwdenk 			dev_desc->vendor,
68affae2bfSwdenk 			dev_desc->product,
69affae2bfSwdenk 			dev_desc->revision);
70affae2bfSwdenk 	}
71affae2bfSwdenk 	puts ("            Type: ");
72affae2bfSwdenk 	if (dev_desc->removable)
73affae2bfSwdenk 		puts ("Removable ");
74affae2bfSwdenk 	switch (dev_desc->type & 0x1F) {
75affae2bfSwdenk 		case DEV_TYPE_HARDDISK: puts ("Hard Disk");
76affae2bfSwdenk 					break;
77affae2bfSwdenk 		case DEV_TYPE_CDROM: 	puts ("CD ROM");
78affae2bfSwdenk 					break;
79affae2bfSwdenk 		case DEV_TYPE_OPDISK: 	puts ("Optical Device");
80affae2bfSwdenk 					break;
81affae2bfSwdenk 		case DEV_TYPE_TAPE: 	puts ("Tape");
82affae2bfSwdenk 					break;
83affae2bfSwdenk 		default:		printf ("# %02X #", dev_desc->type & 0x1F);
84affae2bfSwdenk 					break;
85affae2bfSwdenk 	}
86affae2bfSwdenk 	puts ("\n");
87affae2bfSwdenk 	if ((dev_desc->lba * dev_desc->blksz)>0L) {
88affae2bfSwdenk 		ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
89*c40b2956Swdenk 		lbaint_t lba;
90*c40b2956Swdenk #if CONFIG_LBA48
91*c40b2956Swdenk 		if (dev_desc->lba48support)
92*c40b2956Swdenk 			lba = dev_desc->lba48;
93*c40b2956Swdenk 		else
94*c40b2956Swdenk #endif
95*c40b2956Swdenk 			lba = dev_desc->lba;
96affae2bfSwdenk 
97*c40b2956Swdenk 		lba512 = (lba * (dev_desc->blksz/512));
98affae2bfSwdenk 		mb = (10 * lba512) / 2048;	/* 2048 = (1024 * 1024) / 512 MB */
99affae2bfSwdenk 		/* round to 1 digit */
100affae2bfSwdenk 		mb_quot	= mb / 10;
101affae2bfSwdenk 		mb_rem	= mb - (10 * mb_quot);
102affae2bfSwdenk 
103affae2bfSwdenk 		gb = mb / 1024;
104affae2bfSwdenk 		gb_quot	= gb / 10;
105affae2bfSwdenk 		gb_rem	= gb - (10 * gb_quot);
106*c40b2956Swdenk #if CONFIG_LBA48
107*c40b2956Swdenk 		if (dev_desc->lba48support)
108*c40b2956Swdenk 			printf ("            Supports 48-bit addressing\n");
109*c40b2956Swdenk #endif
110*c40b2956Swdenk #if CFG_64BIT_LBA && CFG_64BIT_VSPRINTF
111*c40b2956Swdenk 		printf ("            Capacity: %ld.%ld MB = %ld.%ld GB (%qd x %ld)\n",
112*c40b2956Swdenk 			mb_quot, mb_rem,
113*c40b2956Swdenk 			gb_quot, gb_rem,
114*c40b2956Swdenk 			lba,
115*c40b2956Swdenk 			dev_desc->blksz);
116*c40b2956Swdenk #else
117affae2bfSwdenk 		printf ("            Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n",
118affae2bfSwdenk 			mb_quot, mb_rem,
119affae2bfSwdenk 			gb_quot, gb_rem,
120*c40b2956Swdenk 			(ulong)lba,
121affae2bfSwdenk 			dev_desc->blksz);
122*c40b2956Swdenk #endif
123affae2bfSwdenk 	} else {
124affae2bfSwdenk 		puts ("            Capacity: not available\n");
125affae2bfSwdenk 	}
126affae2bfSwdenk }
127c935d3bdSwdenk #endif	/* CFG_CMD_IDE || CFG_CMD_SCSI || CFG_CMD_USB || CONFIG_MMC */
128affae2bfSwdenk 
129c935d3bdSwdenk #if ((CONFIG_COMMANDS & CFG_CMD_IDE)	|| \
130c935d3bdSwdenk      (CONFIG_COMMANDS & CFG_CMD_SCSI)	|| \
1313f85ce27Swdenk      (CONFIG_COMMANDS & CFG_CMD_USB)	|| \
1323f85ce27Swdenk      defined(CONFIG_SYSTEMACE)          )
133affae2bfSwdenk 
134affae2bfSwdenk #if defined(CONFIG_MAC_PARTITION) || \
135affae2bfSwdenk     defined(CONFIG_DOS_PARTITION) || \
136c7de829cSwdenk     defined(CONFIG_ISO_PARTITION) || \
137c7de829cSwdenk     defined(CONFIG_AMIGA_PARTITION)
138affae2bfSwdenk 
139affae2bfSwdenk void init_part (block_dev_desc_t * dev_desc)
140affae2bfSwdenk {
141affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION
142affae2bfSwdenk 	if (test_part_iso(dev_desc) == 0) {
143affae2bfSwdenk 		dev_desc->part_type = PART_TYPE_ISO;
144affae2bfSwdenk 		return;
145affae2bfSwdenk 	}
146affae2bfSwdenk #endif
147affae2bfSwdenk 
148affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION
149affae2bfSwdenk 	if (test_part_mac(dev_desc) == 0) {
150affae2bfSwdenk 		dev_desc->part_type = PART_TYPE_MAC;
151affae2bfSwdenk 		return;
152affae2bfSwdenk 	}
153affae2bfSwdenk #endif
154affae2bfSwdenk 
155affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION
156affae2bfSwdenk 	if (test_part_dos(dev_desc) == 0) {
157affae2bfSwdenk 		dev_desc->part_type = PART_TYPE_DOS;
158affae2bfSwdenk 		return;
159affae2bfSwdenk 	}
160affae2bfSwdenk #endif
161c7de829cSwdenk 
162c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION
163c7de829cSwdenk 	if (test_part_amiga(dev_desc) == 0) {
164c7de829cSwdenk 	    dev_desc->part_type = PART_TYPE_AMIGA;
165c7de829cSwdenk 	    return;
166c7de829cSwdenk 	}
167c7de829cSwdenk #endif
168affae2bfSwdenk }
169affae2bfSwdenk 
170affae2bfSwdenk 
171affae2bfSwdenk int get_partition_info (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
172affae2bfSwdenk {
173affae2bfSwdenk 		switch (dev_desc->part_type) {
174affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION
175affae2bfSwdenk 	case PART_TYPE_MAC:
176affae2bfSwdenk 		if (get_partition_info_mac(dev_desc,part,info) == 0) {
177affae2bfSwdenk 			PRINTF ("## Valid MAC partition found ##\n");
178affae2bfSwdenk 			return (0);
179affae2bfSwdenk 		}
180affae2bfSwdenk 		break;
181affae2bfSwdenk #endif
182affae2bfSwdenk 
183affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION
184affae2bfSwdenk 	case PART_TYPE_DOS:
185affae2bfSwdenk 		if (get_partition_info_dos(dev_desc,part,info) == 0) {
186affae2bfSwdenk 			PRINTF ("## Valid DOS partition found ##\n");
187affae2bfSwdenk 			return (0);
188affae2bfSwdenk 		}
189affae2bfSwdenk 		break;
190affae2bfSwdenk #endif
191affae2bfSwdenk 
192affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION
193affae2bfSwdenk 	case PART_TYPE_ISO:
194affae2bfSwdenk 		if (get_partition_info_iso(dev_desc,part,info) == 0) {
195affae2bfSwdenk 			PRINTF ("## Valid ISO boot partition found ##\n");
196affae2bfSwdenk 			return (0);
197affae2bfSwdenk 		}
198affae2bfSwdenk 		break;
199affae2bfSwdenk #endif
200c7de829cSwdenk 
201c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION
202c7de829cSwdenk 	case PART_TYPE_AMIGA:
203c7de829cSwdenk 	    if (get_partition_info_amiga(dev_desc, part, info) == 0)
204c7de829cSwdenk 	    {
205c7de829cSwdenk 		PRINTF ("## Valid Amiga partition found ##\n");
206c7de829cSwdenk 		return (0);
207c7de829cSwdenk 	    }
208c7de829cSwdenk 	    break;
209c7de829cSwdenk #endif
210affae2bfSwdenk 	default:
211affae2bfSwdenk 		break;
212affae2bfSwdenk 	}
213affae2bfSwdenk 	return (-1);
214affae2bfSwdenk }
215affae2bfSwdenk 
216affae2bfSwdenk static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
217affae2bfSwdenk {
218affae2bfSwdenk 	puts ("\nPartition Map for ");
219affae2bfSwdenk 	switch (dev_desc->if_type) {
220affae2bfSwdenk 		case IF_TYPE_IDE:  	puts ("IDE");
221affae2bfSwdenk 					break;
222affae2bfSwdenk 		case IF_TYPE_SCSI: 	puts ("SCSI");
223affae2bfSwdenk 					break;
224affae2bfSwdenk 		case IF_TYPE_ATAPI:	puts ("ATAPI");
225affae2bfSwdenk 					break;
226affae2bfSwdenk 		case IF_TYPE_USB:	puts ("USB");
227affae2bfSwdenk 					break;
228affae2bfSwdenk 		case IF_TYPE_DOC:	puts ("DOC");
229affae2bfSwdenk 					break;
230affae2bfSwdenk 		default: 		puts ("UNKNOWN");
231affae2bfSwdenk 					break;
232affae2bfSwdenk 	}
233affae2bfSwdenk 	printf (" device %d  --   Partition Type: %s\n\n",
234affae2bfSwdenk 			dev_desc->dev, type);
235affae2bfSwdenk }
236affae2bfSwdenk 
237affae2bfSwdenk void print_part (block_dev_desc_t * dev_desc)
238affae2bfSwdenk {
239affae2bfSwdenk 
240affae2bfSwdenk 		switch (dev_desc->part_type) {
241affae2bfSwdenk #ifdef CONFIG_MAC_PARTITION
242affae2bfSwdenk 	case PART_TYPE_MAC:
243affae2bfSwdenk 		PRINTF ("## Testing for valid MAC partition ##\n");
244affae2bfSwdenk 		print_part_header ("MAC", dev_desc);
245affae2bfSwdenk 		print_part_mac (dev_desc);
246affae2bfSwdenk 		return;
247affae2bfSwdenk #endif
248affae2bfSwdenk #ifdef CONFIG_DOS_PARTITION
249affae2bfSwdenk 	case PART_TYPE_DOS:
250affae2bfSwdenk 		PRINTF ("## Testing for valid DOS partition ##\n");
251affae2bfSwdenk 		print_part_header ("DOS", dev_desc);
252affae2bfSwdenk 		print_part_dos (dev_desc);
253affae2bfSwdenk 		return;
254affae2bfSwdenk #endif
255affae2bfSwdenk 
256affae2bfSwdenk #ifdef CONFIG_ISO_PARTITION
257affae2bfSwdenk 	case PART_TYPE_ISO:
258affae2bfSwdenk 		PRINTF ("## Testing for valid ISO Boot partition ##\n");
259affae2bfSwdenk 		print_part_header ("ISO", dev_desc);
260affae2bfSwdenk 		print_part_iso (dev_desc);
261affae2bfSwdenk 		return;
262affae2bfSwdenk #endif
263c7de829cSwdenk 
264c7de829cSwdenk #ifdef CONFIG_AMIGA_PARTITION
265c7de829cSwdenk 	case PART_TYPE_AMIGA:
266c7de829cSwdenk 	    PRINTF ("## Testing for a valid Amiga partition ##\n");
267c7de829cSwdenk 	    print_part_header ("AMIGA", dev_desc);
268c7de829cSwdenk 	    print_part_amiga (dev_desc);
269c7de829cSwdenk 	    return;
270c7de829cSwdenk #endif
271affae2bfSwdenk 	}
272affae2bfSwdenk 	puts ("## Unknown partition table\n");
273affae2bfSwdenk }
274affae2bfSwdenk 
275affae2bfSwdenk 
276affae2bfSwdenk #else	/* neither MAC nor DOS nor ISO partition configured */
277affae2bfSwdenk # error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION nor CONFIG_ISO_PARTITION configured!
278affae2bfSwdenk #endif
279affae2bfSwdenk 
280affae2bfSwdenk #endif	/* (CONFIG_COMMANDS & CFG_CMD_IDE) || CONFIG_COMMANDS & CFG_CMD_SCSI) */
281