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,
25 * Support for harddisk partitions.
27 * To be compatible with LinuxPPC and Apple we use the standard Apple
28 * SCSI disk partitioning scheme. For more information see:
29 * http://developer.apple.com/techpubs/mac/Devices/Devices-126.html#MARKER-14-92
37 #if defined(CONFIG_CMD_IDE) || \
38 defined(CONFIG_CMD_MG_DISK) || \
39 defined(CONFIG_CMD_SCSI) || \
40 defined(CONFIG_CMD_SATA) || \
41 defined(CONFIG_CMD_USB) || \
42 defined(CONFIG_MMC) || \
43 defined(CONFIG_SYSTEMACE)
45 /* stdlib.h causes some compatibility problems; should fixe these! -- wd */
46 #ifndef __ldiv_t_defined
48 long int quot; /* Quotient */
49 long int rem; /* Remainder */
51 extern ldiv_t ldiv (long int __numer, long int __denom);
52 # define __ldiv_t_defined 1
56 static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p);
57 static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p);
60 * Test for a valid MAC partition
62 int test_part_mac (block_dev_desc_t *dev_desc)
64 mac_driver_desc_t ddesc;
65 mac_partition_t mpart;
68 if (part_mac_read_ddb (dev_desc, &ddesc)) {
69 /* error reading Driver Desriptor Block, or no valid Signature */
73 n = 1; /* assuming at least one partition */
74 for (i=1; i<=n; ++i) {
75 if ((dev_desc->block_read(dev_desc->dev, i, 1, (ulong *)&mpart) != 1) ||
76 (mpart.signature != MAC_PARTITION_MAGIC) ) {
79 /* update partition count */
86 void print_part_mac (block_dev_desc_t *dev_desc)
89 mac_driver_desc_t ddesc;
90 mac_partition_t mpart;
93 if (part_mac_read_ddb (dev_desc, &ddesc)) {
94 /* error reading Driver Desriptor Block, or no valid Signature */
100 mb = ldiv(n, ((1024 * 1024) / ddesc.blk_size)); /* MB */
101 /* round to 1 digit */
102 mb.rem *= 10 * ddesc.blk_size;
103 mb.rem += 512 * 1024;
104 mb.rem /= 1024 * 1024;
106 gb = ldiv(10 * mb.quot + mb.rem, 10240);
111 printf ("Block Size=%d, Number of Blocks=%d, "
112 "Total Capacity: %ld.%ld MB = %ld.%ld GB\n"
113 "DeviceType=0x%x, DeviceId=0x%x\n\n"
115 " length base (size)\n",
118 mb.quot, mb.rem, gb.quot, gb.rem,
119 ddesc.dev_type, ddesc.dev_id
122 n = 1; /* assuming at least one partition */
123 for (i=1; i<=n; ++i) {
127 printf ("%4ld: ", i);
128 if (dev_desc->block_read (dev_desc->dev, i, 1, (ulong *)&mpart) != 1) {
129 printf ("** Can't read Partition Map on %d:%ld **\n",
134 if (mpart.signature != MAC_PARTITION_MAGIC) {
135 printf ("** Bad Signature on %d:%ld - "
136 "expected 0x%04x, got 0x%04x\n",
137 dev_desc->dev, i, MAC_PARTITION_MAGIC, mpart.signature);
141 /* update partition count */
145 bytes = mpart.block_count;
146 bytes /= (1024 / ddesc.blk_size); /* kB; assumes blk_size == 512 */
156 printf ("%20.32s %-18.32s %10u @ %-10u (%3ld%c)\n",
170 * Read Device Descriptor Block
172 static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p)
174 if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)ddb_p) != 1) {
175 printf ("** Can't read Driver Desriptor Block **\n");
179 if (ddb_p->signature != MAC_DRIVER_MAGIC) {
181 printf ("** Bad Signature: expected 0x%04x, got 0x%04x\n",
182 MAC_DRIVER_MAGIC, ddb_p->signature);
190 * Read Partition Descriptor Block
192 static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p)
198 * We must always read the descritpor block for
199 * partition 1 first since this is the only way to
200 * know how many partitions we have.
202 if (dev_desc->block_read (dev_desc->dev, n, 1, (ulong *)pdb_p) != 1) {
203 printf ("** Can't read Partition Map on %d:%d **\n",
208 if (pdb_p->signature != MAC_PARTITION_MAGIC) {
209 printf ("** Bad Signature on %d:%d: "
210 "expected 0x%04x, got 0x%04x\n",
211 dev_desc->dev, n, MAC_PARTITION_MAGIC, pdb_p->signature);
218 if ((part < 1) || (part > pdb_p->map_count)) {
219 printf ("** Invalid partition %d:%d [%d:1...%d:%d only]\n",
222 dev_desc->dev, pdb_p->map_count);
226 /* update partition count */
233 int get_partition_info_mac (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
235 mac_driver_desc_t ddesc;
236 mac_partition_t mpart;
238 if (part_mac_read_ddb (dev_desc, &ddesc)) {
242 info->blksz = ddesc.blk_size;
244 if (part_mac_read_pdb (dev_desc, part, &mpart)) {
248 info->start = mpart.start_block;
249 info->size = mpart.block_count;
250 memcpy (info->type, mpart.type, sizeof(info->type));
251 memcpy (info->name, mpart.name, sizeof(info->name));