1 // SPDX-License-Identifier: GPL-2.0+
8 * Support for harddisk partitions.
10 * To be compatible with LinuxPPC and Apple we use the standard Apple
11 * SCSI disk partitioning scheme. For more information see:
12 * http://developer.apple.com/techpubs/mac/Devices/Devices-126.html#MARKER-14-92
23 /* stdlib.h causes some compatibility problems; should fixe these! -- wd */
24 #ifndef __ldiv_t_defined
26 long int quot; /* Quotient */
27 long int rem; /* Remainder */
29 extern ldiv_t ldiv (long int __numer, long int __denom);
30 # define __ldiv_t_defined 1
34 static int part_mac_read_ddb(struct blk_desc *desc, mac_driver_desc_t *ddb_p);
35 static int part_mac_read_pdb(struct blk_desc *desc, int part,
36 mac_partition_t *pdb_p);
39 * Test for a valid MAC partition
41 static int part_test_mac(struct blk_desc *desc)
43 ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
44 ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
47 if (part_mac_read_ddb(desc, ddesc)) {
49 * error reading Driver Descriptor Block,
50 * or no valid Signature
55 n = 1; /* assuming at least one partition */
56 for (i=1; i<=n; ++i) {
57 if ((blk_dread(desc, i, 1, (ulong *)mpart) != 1) ||
58 mpart->signature != MAC_PARTITION_MAGIC) {
61 /* update partition count */
67 static void part_print_mac(struct blk_desc *desc)
70 ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
71 ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
74 if (part_mac_read_ddb(desc, ddesc)) {
76 * error reading Driver Descriptor Block,
77 * or no valid Signature
84 mb = ldiv(n, ((1024 * 1024) / ddesc->blk_size)); /* MB */
85 /* round to 1 digit */
86 mb.rem *= 10 * ddesc->blk_size;
88 mb.rem /= 1024 * 1024;
90 gb = ldiv(10 * mb.quot + mb.rem, 10240);
95 printf ("Block Size=%d, Number of Blocks=%d, "
96 "Total Capacity: %ld.%ld MB = %ld.%ld GB\n"
97 "DeviceType=0x%x, DeviceId=0x%x\n\n"
99 " length base (size)\n",
102 mb.quot, mb.rem, gb.quot, gb.rem,
103 ddesc->dev_type, ddesc->dev_id
106 n = 1; /* assuming at least one partition */
107 for (i=1; i<=n; ++i) {
111 printf ("%4ld: ", i);
112 if (blk_dread(desc, i, 1, (ulong *)mpart) != 1) {
113 printf ("** Can't read Partition Map on %d:%ld **\n",
118 if (mpart->signature != MAC_PARTITION_MAGIC) {
119 printf("** Bad Signature on %d:%ld - expected 0x%04x, got 0x%04x\n",
120 desc->devnum, i, MAC_PARTITION_MAGIC,
125 /* update partition count */
126 n = mpart->map_count;
129 bytes = mpart->block_count;
130 bytes /= (1024 / ddesc->blk_size); /* kB; assumes blk_size == 512 */
140 printf ("%20.32s %-18.32s %10u @ %-10u (%3ld%c)\n",
154 * Read Device Descriptor Block
156 static int part_mac_read_ddb(struct blk_desc *desc, mac_driver_desc_t *ddb_p)
158 if (blk_dread(desc, 0, 1, (ulong *)ddb_p) != 1) {
159 debug("** Can't read Driver Descriptor Block **\n");
163 if (ddb_p->signature != MAC_DRIVER_MAGIC) {
170 * Read Partition Descriptor Block
172 static int part_mac_read_pdb(struct blk_desc *desc, int part,
173 mac_partition_t *pdb_p)
179 * We must always read the descritpor block for
180 * partition 1 first since this is the only way to
181 * know how many partitions we have.
183 if (blk_dread(desc, n, 1, (ulong *)pdb_p) != 1) {
184 printf("** Can't read Partition Map on %d:%d **\n",
189 if (pdb_p->signature != MAC_PARTITION_MAGIC) {
190 printf("** Bad Signature on %d:%d: expected 0x%04x, got 0x%04x\n",
191 desc->devnum, n, MAC_PARTITION_MAGIC,
199 if ((part < 1) || (part > pdb_p->map_count)) {
200 printf("** Invalid partition %d:%d [%d:1...%d:%d only]\n",
201 desc->devnum, part, desc->devnum, desc->devnum,
206 /* update partition count */
213 static int part_get_info_mac(struct blk_desc *desc, int part,
214 struct disk_partition *info)
216 ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
217 ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
219 if (part_mac_read_ddb(desc, ddesc))
222 info->blksz = ddesc->blk_size;
224 if (part_mac_read_pdb(desc, part, mpart))
227 info->start = mpart->start_block;
228 info->size = mpart->block_count;
229 memcpy (info->type, mpart->type, sizeof(info->type));
230 memcpy (info->name, mpart->name, sizeof(info->name));
235 U_BOOT_PART_TYPE(mac) = {
237 .part_type = PART_TYPE_MAC,
238 .max_entries = MAC_ENTRY_NUMBERS,
239 .get_info = part_get_info_mac,
240 .print = part_print_mac,
241 .test = part_test_mac,