Blame view
disk/part_mac.c
5.53 KB
fe8c2806c Initial revision |
1 2 3 4 |
/* * (C) Copyright 2000 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
fe8c2806c Initial revision |
6 7 8 9 10 11 12 13 14 15 16 17 |
*/ /* * Support for harddisk partitions. * * To be compatible with LinuxPPC and Apple we use the standard Apple * SCSI disk partitioning scheme. For more information see: * http://developer.apple.com/techpubs/mac/Devices/Devices-126.html#MARKER-14-92 */ #include <common.h> #include <command.h> |
cf92e05c0 Move ALLOC_CACHE_... |
18 |
#include <memalign.h> |
fe8c2806c Initial revision |
19 |
#include <ide.h> |
fe8c2806c Initial revision |
20 |
#include "part_mac.h" |
1811a928c Move most CONFIG_... |
21 |
#ifdef CONFIG_HAVE_BLOCK_DEVICE |
fe8c2806c Initial revision |
22 23 24 25 26 27 28 29 30 31 |
/* stdlib.h causes some compatibility problems; should fixe these! -- wd */ #ifndef __ldiv_t_defined typedef struct { long int quot; /* Quotient */ long int rem; /* Remainder */ } ldiv_t; extern ldiv_t ldiv (long int __numer, long int __denom); # define __ldiv_t_defined 1 #endif |
4101f6879 dm: Drop the bloc... |
32 33 34 35 |
static int part_mac_read_ddb(struct blk_desc *dev_desc, mac_driver_desc_t *ddb_p); static int part_mac_read_pdb(struct blk_desc *dev_desc, int part, mac_partition_t *pdb_p); |
fe8c2806c Initial revision |
36 37 38 39 |
/* * Test for a valid MAC partition */ |
084bf4c24 part: Rename test... |
40 |
static int part_test_mac(struct blk_desc *dev_desc) |
fe8c2806c Initial revision |
41 |
{ |
64a08a9ff part_mac: dcache:... |
42 43 |
ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1); ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1); |
fe8c2806c Initial revision |
44 |
ulong i, n; |
64a08a9ff part_mac: dcache:... |
45 |
if (part_mac_read_ddb (dev_desc, ddesc)) { |
5eae466ea disk: part: fix typo |
46 47 48 49 |
/* * error reading Driver Descriptor Block, * or no valid Signature */ |
fe8c2806c Initial revision |
50 51 52 53 54 |
return (-1); } n = 1; /* assuming at least one partition */ for (i=1; i<=n; ++i) { |
2a981dc2c dm: block: Adjust... |
55 |
if ((blk_dread(dev_desc, i, 1, (ulong *)mpart) != 1) || |
64a08a9ff part_mac: dcache:... |
56 |
(mpart->signature != MAC_PARTITION_MAGIC) ) { |
fe8c2806c Initial revision |
57 58 59 |
return (-1); } /* update partition count */ |
64a08a9ff part_mac: dcache:... |
60 |
n = mpart->map_count; |
fe8c2806c Initial revision |
61 62 63 |
} return (0); } |
084bf4c24 part: Rename test... |
64 |
static void part_print_mac(struct blk_desc *dev_desc) |
fe8c2806c Initial revision |
65 66 |
{ ulong i, n; |
64a08a9ff part_mac: dcache:... |
67 68 |
ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1); ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1); |
fe8c2806c Initial revision |
69 |
ldiv_t mb, gb; |
64a08a9ff part_mac: dcache:... |
70 |
if (part_mac_read_ddb (dev_desc, ddesc)) { |
5eae466ea disk: part: fix typo |
71 72 73 74 |
/* * error reading Driver Descriptor Block, * or no valid Signature */ |
fe8c2806c Initial revision |
75 76 |
return; } |
64a08a9ff part_mac: dcache:... |
77 |
n = ddesc->blk_count; |
fe8c2806c Initial revision |
78 |
|
64a08a9ff part_mac: dcache:... |
79 |
mb = ldiv(n, ((1024 * 1024) / ddesc->blk_size)); /* MB */ |
fe8c2806c Initial revision |
80 |
/* round to 1 digit */ |
64a08a9ff part_mac: dcache:... |
81 |
mb.rem *= 10 * ddesc->blk_size; |
fe8c2806c Initial revision |
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
mb.rem += 512 * 1024; mb.rem /= 1024 * 1024; gb = ldiv(10 * mb.quot + mb.rem, 10240); gb.rem += 512; gb.rem /= 1024; printf ("Block Size=%d, Number of Blocks=%d, " "Total Capacity: %ld.%ld MB = %ld.%ld GB " "DeviceType=0x%x, DeviceId=0x%x " " #: type name" " length base (size) ", |
64a08a9ff part_mac: dcache:... |
99 100 |
ddesc->blk_size, ddesc->blk_count, |
fe8c2806c Initial revision |
101 |
mb.quot, mb.rem, gb.quot, gb.rem, |
64a08a9ff part_mac: dcache:... |
102 |
ddesc->dev_type, ddesc->dev_id |
fe8c2806c Initial revision |
103 104 105 106 107 108 109 110 |
); n = 1; /* assuming at least one partition */ for (i=1; i<=n; ++i) { ulong bytes; char c; printf ("%4ld: ", i); |
2a981dc2c dm: block: Adjust... |
111 |
if (blk_dread(dev_desc, i, 1, (ulong *)mpart) != 1) { |
fe8c2806c Initial revision |
112 113 |
printf ("** Can't read Partition Map on %d:%ld ** ", |
bcce53d04 dm: block: Rename... |
114 |
dev_desc->devnum, i); |
fe8c2806c Initial revision |
115 116 |
return; } |
64a08a9ff part_mac: dcache:... |
117 |
if (mpart->signature != MAC_PARTITION_MAGIC) { |
bcce53d04 dm: block: Rename... |
118 119 120 121 |
printf("** Bad Signature on %d:%ld - expected 0x%04x, got 0x%04x ", dev_desc->devnum, i, MAC_PARTITION_MAGIC, mpart->signature); |
fe8c2806c Initial revision |
122 123 124 125 |
return; } /* update partition count */ |
64a08a9ff part_mac: dcache:... |
126 |
n = mpart->map_count; |
fe8c2806c Initial revision |
127 128 |
c = 'k'; |
64a08a9ff part_mac: dcache:... |
129 130 |
bytes = mpart->block_count; bytes /= (1024 / ddesc->blk_size); /* kB; assumes blk_size == 512 */ |
fe8c2806c Initial revision |
131 132 133 134 135 136 137 138 139 140 141 |
if (bytes >= 1024) { bytes >>= 10; c = 'M'; } if (bytes >= 1024) { bytes >>= 10; c = 'G'; } printf ("%20.32s %-18.32s %10u @ %-10u (%3ld%c) ", |
64a08a9ff part_mac: dcache:... |
142 143 144 145 |
mpart->type, mpart->name, mpart->block_count, mpart->start_block, |
fe8c2806c Initial revision |
146 147 148 149 150 151 152 153 154 155 156 |
bytes, c ); } return; } /* * Read Device Descriptor Block */ |
4101f6879 dm: Drop the bloc... |
157 158 |
static int part_mac_read_ddb(struct blk_desc *dev_desc, mac_driver_desc_t *ddb_p) |
fe8c2806c Initial revision |
159 |
{ |
2a981dc2c dm: block: Adjust... |
160 |
if (blk_dread(dev_desc, 0, 1, (ulong *)ddb_p) != 1) { |
337e3b897 part: mac: Suppre... |
161 162 |
debug("** Can't read Driver Descriptor Block ** "); |
fe8c2806c Initial revision |
163 164 165 166 |
return (-1); } if (ddb_p->signature != MAC_DRIVER_MAGIC) { |
fe8c2806c Initial revision |
167 168 169 170 171 172 173 174 |
return (-1); } return (0); } /* * Read Partition Descriptor Block */ |
4101f6879 dm: Drop the bloc... |
175 176 |
static int part_mac_read_pdb(struct blk_desc *dev_desc, int part, mac_partition_t *pdb_p) |
fe8c2806c Initial revision |
177 178 179 180 181 |
{ int n = 1; for (;;) { /* |
8bde7f776 * Code cleanup: |
182 183 184 |
* We must always read the descritpor block for * partition 1 first since this is the only way to * know how many partitions we have. |
fe8c2806c Initial revision |
185 |
*/ |
2a981dc2c dm: block: Adjust... |
186 |
if (blk_dread(dev_desc, n, 1, (ulong *)pdb_p) != 1) { |
fe8c2806c Initial revision |
187 188 |
printf ("** Can't read Partition Map on %d:%d ** ", |
bcce53d04 dm: block: Rename... |
189 |
dev_desc->devnum, n); |
fe8c2806c Initial revision |
190 191 192 193 |
return (-1); } if (pdb_p->signature != MAC_PARTITION_MAGIC) { |
bcce53d04 dm: block: Rename... |
194 195 196 197 |
printf("** Bad Signature on %d:%d: expected 0x%04x, got 0x%04x ", dev_desc->devnum, n, MAC_PARTITION_MAGIC, pdb_p->signature); |
fe8c2806c Initial revision |
198 199 200 201 202 203 204 205 206 |
return (-1); } if (n == part) return (0); if ((part < 1) || (part > pdb_p->map_count)) { printf ("** Invalid partition %d:%d [%d:1...%d:%d only] ", |
bcce53d04 dm: block: Rename... |
207 208 209 |
dev_desc->devnum, part, dev_desc->devnum, dev_desc->devnum, pdb_p->map_count); |
fe8c2806c Initial revision |
210 211 212 213 214 215 216 217 218 |
return (-1); } /* update partition count */ n = part; } /* NOTREACHED */ } |
3e8bd4695 dm: part: Rename ... |
219 |
static int part_get_info_mac(struct blk_desc *dev_desc, int part, |
96e5b03c8 dm: part: Convert... |
220 |
disk_partition_t *info) |
fe8c2806c Initial revision |
221 |
{ |
64a08a9ff part_mac: dcache:... |
222 223 |
ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1); ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1); |
fe8c2806c Initial revision |
224 |
|
64a08a9ff part_mac: dcache:... |
225 |
if (part_mac_read_ddb (dev_desc, ddesc)) { |
fe8c2806c Initial revision |
226 227 |
return (-1); } |
64a08a9ff part_mac: dcache:... |
228 |
info->blksz = ddesc->blk_size; |
fe8c2806c Initial revision |
229 |
|
64a08a9ff part_mac: dcache:... |
230 |
if (part_mac_read_pdb (dev_desc, part, mpart)) { |
fe8c2806c Initial revision |
231 232 |
return (-1); } |
64a08a9ff part_mac: dcache:... |
233 234 235 236 |
info->start = mpart->start_block; info->size = mpart->block_count; memcpy (info->type, mpart->type, sizeof(info->type)); memcpy (info->name, mpart->name, sizeof(info->name)); |
fe8c2806c Initial revision |
237 238 239 |
return (0); } |
96e5b03c8 dm: part: Convert... |
240 241 242 |
U_BOOT_PART_TYPE(mac) = { .name = "MAC", .part_type = PART_TYPE_MAC, |
87b8530fe disk: part: imple... |
243 |
.max_entries = MAC_ENTRY_NUMBERS, |
3e8bd4695 dm: part: Rename ... |
244 |
.get_info = part_get_info_mac, |
084bf4c24 part: Rename test... |
245 246 |
.print = part_print_mac, .test = part_test_mac, |
96e5b03c8 dm: part: Convert... |
247 |
}; |
cde5c64d1 disk/: Remove obs... |
248 |
#endif |