]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
ff6e181a A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
1c79356b | 12 | * |
ff6e181a A |
13 | * The Original Code and all software distributed under the License are |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
ff6e181a A |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
1c79356b A |
20 | * |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | #include <IOKit/IOBSD.h> | |
24 | #include <IOKit/IOLib.h> | |
25 | #include <IOKit/IOService.h> | |
26 | #include <IOKit/IODeviceTreeSupport.h> | |
27 | #include <IOKit/IOKitKeys.h> | |
1c79356b A |
28 | #include <IOKit/IOPlatformExpert.h> |
29 | ||
1c79356b A |
30 | extern "C" { |
31 | ||
32 | #include <pexpert/pexpert.h> | |
33 | #include <kern/clock.h> | |
34 | ||
35 | // how long to wait for matching root device, secs | |
36 | #define ROOTDEVICETIMEOUT 60 | |
37 | ||
55e303ae A |
38 | extern dev_t mdevadd(int devid, ppnum_t base, unsigned int size, int phys); |
39 | extern dev_t mdevlookup(int devid); | |
1c79356b A |
40 | |
41 | kern_return_t | |
42 | IOKitBSDInit( void ) | |
43 | { | |
1c79356b A |
44 | IOService::publishResource("IOBSD"); |
45 | ||
46 | return( kIOReturnSuccess ); | |
47 | } | |
48 | ||
49 | OSDictionary * IOBSDNameMatching( const char * name ) | |
50 | { | |
51 | OSDictionary * dict; | |
52 | const OSSymbol * str = 0; | |
53 | ||
54 | do { | |
55 | ||
56 | dict = IOService::serviceMatching( gIOServiceKey ); | |
57 | if( !dict) | |
58 | continue; | |
59 | str = OSSymbol::withCString( name ); | |
60 | if( !str) | |
61 | continue; | |
62 | dict->setObject( kIOBSDNameKey, (OSObject *) str ); | |
63 | str->release(); | |
64 | ||
65 | return( dict ); | |
66 | ||
67 | } while( false ); | |
68 | ||
69 | if( dict) | |
70 | dict->release(); | |
71 | if( str) | |
72 | str->release(); | |
73 | ||
74 | return( 0 ); | |
75 | } | |
76 | ||
91447636 A |
77 | OSDictionary * IOUUIDMatching( void ) |
78 | { | |
79 | return IOService::resourceMatching( "boot-uuid-media" ); | |
80 | } | |
81 | ||
82 | ||
55e303ae | 83 | OSDictionary * IOCDMatching( void ) |
0b4e3aa0 A |
84 | { |
85 | OSDictionary * dict; | |
86 | const OSSymbol * str; | |
55e303ae A |
87 | |
88 | dict = IOService::serviceMatching( "IOMedia" ); | |
89 | if( dict == 0 ) { | |
90 | IOLog("Unable to find IOMedia\n"); | |
91 | return 0; | |
92 | } | |
93 | ||
94 | str = OSSymbol::withCString( "CD_ROM_Mode_1" ); | |
95 | if( str == 0 ) { | |
96 | dict->release(); | |
97 | return 0; | |
98 | } | |
99 | ||
100 | dict->setObject( "Content Hint", (OSObject *)str ); | |
101 | str->release(); | |
102 | return( dict ); | |
0b4e3aa0 A |
103 | } |
104 | ||
1c79356b A |
105 | OSDictionary * IONetworkMatching( const char * path, |
106 | char * buf, int maxLen ) | |
107 | { | |
108 | OSDictionary * matching = 0; | |
109 | OSDictionary * dict; | |
110 | OSString * str; | |
111 | char * comp; | |
112 | const char * skip; | |
113 | int len; | |
114 | ||
115 | do { | |
116 | ||
117 | len = strlen( kIODeviceTreePlane ":" ); | |
118 | maxLen -= len; | |
119 | if( maxLen < 0) | |
120 | continue; | |
121 | ||
122 | strcpy( buf, kIODeviceTreePlane ":" ); | |
123 | comp = buf + len; | |
124 | ||
125 | // remove parameters following ':' from the path | |
126 | skip = strchr( path, ':'); | |
127 | if( !skip) | |
128 | continue; | |
129 | ||
130 | len = skip - path; | |
131 | maxLen -= len; | |
132 | if( maxLen < 0) | |
133 | continue; | |
134 | strncpy( comp, path, len ); | |
135 | comp[ len ] = 0; | |
136 | ||
137 | matching = IOService::serviceMatching( "IONetworkInterface" ); | |
138 | if( !matching) | |
139 | continue; | |
140 | dict = IOService::addLocation( matching ); | |
141 | if( !dict) | |
142 | continue; | |
143 | ||
144 | str = OSString::withCString( buf ); | |
145 | if( !str) | |
146 | continue; | |
147 | dict->setObject( kIOPathMatchKey, str ); | |
148 | str->release(); | |
149 | ||
150 | return( matching ); | |
151 | ||
152 | } while( false ); | |
153 | ||
154 | if( matching) | |
155 | matching->release(); | |
156 | ||
157 | return( 0 ); | |
158 | } | |
159 | ||
160 | OSDictionary * IONetworkNamePrefixMatching( const char * prefix ) | |
161 | { | |
162 | OSDictionary * matching; | |
163 | OSDictionary * propDict = 0; | |
164 | const OSSymbol * str = 0; | |
165 | ||
166 | do { | |
167 | matching = IOService::serviceMatching( "IONetworkInterface" ); | |
168 | if ( matching == 0 ) | |
169 | continue; | |
170 | ||
171 | propDict = OSDictionary::withCapacity(1); | |
172 | if ( propDict == 0 ) | |
173 | continue; | |
174 | ||
175 | str = OSSymbol::withCString( prefix ); | |
176 | if ( str == 0 ) | |
177 | continue; | |
178 | ||
0b4e3aa0 | 179 | propDict->setObject( "IOInterfaceNamePrefix", (OSObject *) str ); |
1c79356b A |
180 | str->release(); |
181 | str = 0; | |
182 | ||
183 | if ( matching->setObject( gIOPropertyMatchKey, | |
184 | (OSObject *) propDict ) != true ) | |
185 | continue; | |
186 | ||
187 | propDict->release(); | |
188 | propDict = 0; | |
189 | ||
190 | return( matching ); | |
191 | ||
192 | } while ( false ); | |
193 | ||
194 | if ( matching ) matching->release(); | |
195 | if ( propDict ) propDict->release(); | |
196 | if ( str ) str->release(); | |
197 | ||
198 | return( 0 ); | |
199 | } | |
200 | ||
0b4e3aa0 | 201 | static bool IORegisterNetworkInterface( IOService * netif ) |
1c79356b | 202 | { |
0b4e3aa0 A |
203 | // A network interface is typically named and registered |
204 | // with BSD after receiving a request from a user space | |
205 | // "namer". However, for cases when the system needs to | |
206 | // root from the network, this registration task must be | |
207 | // done inside the kernel and completed before the root | |
208 | // device is handed to BSD. | |
209 | ||
210 | IOService * stack; | |
211 | OSNumber * zero = 0; | |
212 | OSString * path = 0; | |
213 | OSDictionary * dict = 0; | |
214 | char * pathBuf = 0; | |
215 | int len; | |
216 | enum { kMaxPathLen = 512 }; | |
1c79356b | 217 | |
0b4e3aa0 A |
218 | do { |
219 | stack = IOService::waitForService( | |
220 | IOService::serviceMatching("IONetworkStack") ); | |
221 | if ( stack == 0 ) break; | |
1c79356b | 222 | |
0b4e3aa0 A |
223 | dict = OSDictionary::withCapacity(3); |
224 | if ( dict == 0 ) break; | |
1c79356b | 225 | |
0b4e3aa0 A |
226 | zero = OSNumber::withNumber((UInt64) 0, 32); |
227 | if ( zero == 0 ) break; | |
1c79356b | 228 | |
0b4e3aa0 A |
229 | pathBuf = (char *) IOMalloc( kMaxPathLen ); |
230 | if ( pathBuf == 0 ) break; | |
231 | ||
232 | len = kMaxPathLen; | |
233 | if ( netif->getPath( pathBuf, &len, gIOServicePlane ) | |
234 | == false ) break; | |
235 | ||
236 | path = OSString::withCStringNoCopy( pathBuf ); | |
237 | if ( path == 0 ) break; | |
238 | ||
239 | dict->setObject( "IOInterfaceUnit", zero ); | |
240 | dict->setObject( kIOPathMatchKey, path ); | |
241 | ||
242 | stack->setProperties( dict ); | |
243 | } | |
244 | while ( false ); | |
245 | ||
246 | if ( zero ) zero->release(); | |
247 | if ( path ) path->release(); | |
248 | if ( dict ) dict->release(); | |
249 | if ( pathBuf ) IOFree(pathBuf, kMaxPathLen); | |
250 | ||
251 | return ( netif->getProperty( kIOBSDNameKey ) != 0 ); | |
1c79356b A |
252 | } |
253 | ||
254 | OSDictionary * IODiskMatching( const char * path, char * buf, int maxLen ) | |
255 | { | |
256 | const char * look; | |
257 | const char * alias; | |
258 | char * comp; | |
259 | long unit = -1; | |
260 | long partition = -1; | |
55e303ae | 261 | long lun = -1; |
1c79356b A |
262 | char c; |
263 | ||
264 | // scan the tail of the path for "@unit:partition" | |
265 | do { | |
266 | // Have to get the full path to the controller - an alias may | |
267 | // tell us next to nothing, like "hd:8" | |
268 | alias = IORegistryEntry::dealiasPath( &path, gIODTPlane ); | |
55e303ae | 269 | |
1c79356b A |
270 | look = path + strlen( path); |
271 | c = ':'; | |
272 | while( look != path) { | |
273 | if( *(--look) == c) { | |
274 | if( c == ':') { | |
275 | partition = strtol( look + 1, 0, 0 ); | |
276 | c = '@'; | |
277 | } else if( c == '@') { | |
91447636 A |
278 | unit = strtol( look + 1, &comp, 16 ); |
279 | ||
280 | if( *comp == ',') { | |
281 | lun = strtol( comp + 1, 0, 16 ); | |
55e303ae A |
282 | } |
283 | ||
1c79356b A |
284 | c = '/'; |
285 | } else if( c == '/') { | |
286 | c = 0; | |
287 | break; | |
288 | } | |
289 | } | |
290 | ||
291 | if( alias && (look == path)) { | |
292 | path = alias; | |
293 | look = path + strlen( path); | |
294 | alias = 0; | |
295 | } | |
296 | } | |
297 | if( c || unit == -1 || partition == -1) | |
298 | continue; | |
55e303ae | 299 | |
1c79356b A |
300 | maxLen -= strlen( "{" kIOPathMatchKey "='" kIODeviceTreePlane ":" ); |
301 | maxLen -= ( alias ? strlen( alias ) : 0 ) + (look - path); | |
55e303ae | 302 | maxLen -= strlen( "/@hhhhhhhh,hhhhhhhh:dddddddddd';}" ); |
1c79356b A |
303 | |
304 | if( maxLen > 0) { | |
305 | sprintf( buf, "{" kIOPathMatchKey "='" kIODeviceTreePlane ":" ); | |
306 | comp = buf + strlen( buf ); | |
55e303ae | 307 | |
1c79356b A |
308 | if( alias) { |
309 | strcpy( comp, alias ); | |
310 | comp += strlen( alias ); | |
311 | } | |
55e303ae | 312 | |
1c79356b A |
313 | if ( (look - path)) { |
314 | strncpy( comp, path, look - path); | |
315 | comp += look - path; | |
316 | } | |
55e303ae A |
317 | |
318 | if ( lun != -1 ) | |
319 | { | |
320 | sprintf ( comp, "/@%lx,%lx:%ld';}", unit, lun, partition ); | |
321 | } | |
322 | else | |
323 | { | |
324 | sprintf( comp, "/@%lx:%ld';}", unit, partition ); | |
325 | } | |
1c79356b A |
326 | } else |
327 | continue; | |
55e303ae | 328 | |
1c79356b A |
329 | return( OSDynamicCast(OSDictionary, OSUnserialize( buf, 0 )) ); |
330 | ||
331 | } while( false ); | |
332 | ||
333 | return( 0 ); | |
334 | } | |
335 | ||
336 | OSDictionary * IOOFPathMatching( const char * path, char * buf, int maxLen ) | |
337 | { | |
91447636 A |
338 | OSDictionary * matching; |
339 | OSString * str; | |
340 | char * comp; | |
341 | int len; | |
342 | ||
1c79356b A |
343 | /* need to look up path, get device type, |
344 | call matching help based on device type */ | |
345 | ||
91447636 A |
346 | matching = IODiskMatching( path, buf, maxLen ); |
347 | if( matching) | |
348 | return( matching ); | |
349 | ||
350 | do { | |
351 | ||
352 | len = strlen( kIODeviceTreePlane ":" ); | |
353 | maxLen -= len; | |
354 | if( maxLen < 0) | |
355 | continue; | |
356 | ||
357 | strcpy( buf, kIODeviceTreePlane ":" ); | |
358 | comp = buf + len; | |
359 | ||
360 | len = strlen( path ); | |
361 | maxLen -= len; | |
362 | if( maxLen < 0) | |
363 | continue; | |
364 | strncpy( comp, path, len ); | |
365 | comp[ len ] = 0; | |
366 | ||
367 | matching = OSDictionary::withCapacity( 1 ); | |
368 | if( !matching) | |
369 | continue; | |
370 | ||
371 | str = OSString::withCString( buf ); | |
372 | if( !str) | |
373 | continue; | |
374 | matching->setObject( kIOPathMatchKey, str ); | |
375 | str->release(); | |
376 | ||
377 | return( matching ); | |
378 | ||
379 | } while( false ); | |
1c79356b | 380 | |
91447636 A |
381 | if( matching) |
382 | matching->release(); | |
383 | ||
384 | return( 0 ); | |
1c79356b A |
385 | } |
386 | ||
55e303ae A |
387 | IOService * IOFindMatchingChild( IOService * service ) |
388 | { | |
389 | // find a matching child service | |
390 | IOService * child = 0; | |
391 | OSIterator * iter = service->getClientIterator(); | |
392 | if ( iter ) { | |
393 | while( ( child = (IOService *) iter->getNextObject() ) ) { | |
394 | OSDictionary * dict = OSDictionary::withCapacity( 1 ); | |
395 | if( dict == 0 ) { | |
396 | iter->release(); | |
397 | return 0; | |
398 | } | |
399 | const OSSymbol * str = OSSymbol::withCString( "Apple_HFS" ); | |
400 | if( str == 0 ) { | |
401 | dict->release(); | |
402 | iter->release(); | |
403 | return 0; | |
404 | } | |
405 | dict->setObject( "Content", (OSObject *)str ); | |
406 | str->release(); | |
407 | if ( child->compareProperty( dict, "Content" ) ) { | |
408 | dict->release(); | |
409 | break; | |
410 | } | |
411 | dict->release(); | |
412 | IOService * subchild = IOFindMatchingChild( child ); | |
413 | if ( subchild ) { | |
414 | child = subchild; | |
415 | break; | |
416 | } | |
417 | } | |
418 | iter->release(); | |
419 | } | |
420 | return child; | |
421 | } | |
422 | ||
423 | static int didRam = 0; | |
424 | ||
1c79356b A |
425 | kern_return_t IOFindBSDRoot( char * rootName, |
426 | dev_t * root, u_int32_t * oflags ) | |
427 | { | |
428 | mach_timespec_t t; | |
429 | IOService * service; | |
430 | IORegistryEntry * regEntry; | |
431 | OSDictionary * matching = 0; | |
432 | OSString * iostr; | |
433 | OSNumber * off; | |
434 | OSData * data = 0; | |
55e303ae | 435 | UInt32 *ramdParms = 0; |
1c79356b A |
436 | |
437 | UInt32 flags = 0; | |
438 | int minor, major; | |
55e303ae | 439 | bool findHFSChild = false; |
91447636 | 440 | char * mediaProperty = 0; |
1c79356b A |
441 | char * rdBootVar; |
442 | enum { kMaxPathBuf = 512, kMaxBootVar = 128 }; | |
443 | char * str; | |
444 | const char * look = 0; | |
445 | int len; | |
446 | bool forceNet = false; | |
0b4e3aa0 | 447 | bool debugInfoPrintedOnce = false; |
91447636 | 448 | const char * uuidStr = NULL; |
1c79356b A |
449 | |
450 | static int mountAttempts = 0; | |
55e303ae | 451 | |
91447636 | 452 | int xchar, dchar; |
55e303ae | 453 | |
1c79356b A |
454 | |
455 | if( mountAttempts++) | |
456 | IOSleep( 5 * 1000 ); | |
457 | ||
458 | str = (char *) IOMalloc( kMaxPathBuf + kMaxBootVar ); | |
459 | if( !str) | |
460 | return( kIOReturnNoMemory ); | |
461 | rdBootVar = str + kMaxPathBuf; | |
462 | ||
463 | if (!PE_parse_boot_arg("rd", rdBootVar ) | |
464 | && !PE_parse_boot_arg("rootdev", rdBootVar )) | |
465 | rdBootVar[0] = 0; | |
466 | ||
467 | do { | |
91447636 A |
468 | if( (regEntry = IORegistryEntry::fromPath( "/chosen", gIODTPlane ))) { |
469 | data = (OSData *) regEntry->getProperty( "boot-uuid" ); | |
470 | if( data) { | |
471 | uuidStr = (const char*)data->getBytesNoCopy(); | |
472 | OSString *uuidString = OSString::withCString( uuidStr ); | |
473 | ||
474 | // match the boot-args boot-uuid processing below | |
475 | if( uuidString) { | |
476 | IOLog("rooting via boot-uuid from /chosen: %s\n", uuidStr); | |
477 | IOService::publishResource( "boot-uuid", uuidString ); | |
478 | uuidString->release(); | |
479 | matching = IOUUIDMatching(); | |
480 | mediaProperty = "boot-uuid-media"; | |
481 | regEntry->release(); | |
482 | continue; | |
483 | } else { | |
484 | uuidStr = NULL; | |
55e303ae | 485 | } |
91447636 A |
486 | } |
487 | ||
488 | // else try for an OF Path | |
489 | data = (OSData *) regEntry->getProperty( "rootpath" ); | |
490 | regEntry->release(); | |
491 | if( data) continue; | |
492 | } | |
1c79356b | 493 | if( (regEntry = IORegistryEntry::fromPath( "/options", gIODTPlane ))) { |
91447636 A |
494 | data = (OSData *) regEntry->getProperty( "boot-file" ); |
495 | regEntry->release(); | |
496 | if( data) continue; | |
497 | } | |
1c79356b A |
498 | } while( false ); |
499 | ||
91447636 | 500 | if( data && !uuidStr) |
1c79356b A |
501 | look = (const char *) data->getBytesNoCopy(); |
502 | ||
503 | if( rdBootVar[0] == '*') { | |
504 | look = rdBootVar + 1; | |
55e303ae | 505 | forceNet = false; |
1c79356b A |
506 | } else { |
507 | if( (regEntry = IORegistryEntry::fromPath( "/", gIODTPlane ))) { | |
508 | forceNet = (0 != regEntry->getProperty( "net-boot" )); | |
55e303ae A |
509 | regEntry->release(); |
510 | } | |
de355530 | 511 | } |
d7e50217 | 512 | |
55e303ae A |
513 | |
514 | ||
515 | // | |
516 | // See if we have a RAMDisk property in /chosen/memory-map. If so, make it into a device. | |
517 | // It will become /dev/mdx, where x is 0-f. | |
518 | // | |
519 | ||
520 | if(!didRam) { /* Have we already build this ram disk? */ | |
521 | didRam = 1; /* Remember we did this */ | |
522 | if((regEntry = IORegistryEntry::fromPath( "/chosen/memory-map", gIODTPlane ))) { /* Find the map node */ | |
523 | data = (OSData *)regEntry->getProperty("RAMDisk"); /* Find the ram disk, if there */ | |
524 | if(data) { /* We found one */ | |
525 | ||
526 | ramdParms = (UInt32 *)data->getBytesNoCopy(); /* Point to the ram disk base and size */ | |
527 | (void)mdevadd(-1, ramdParms[0] >> 12, ramdParms[1] >> 12, 0); /* Initialize it and pass back the device number */ | |
528 | } | |
529 | regEntry->release(); /* Toss the entry */ | |
530 | } | |
531 | } | |
532 | ||
533 | // | |
534 | // Now check if we are trying to root on a memory device | |
535 | // | |
536 | ||
537 | if((rdBootVar[0] == 'm') && (rdBootVar[1] == 'd') && (rdBootVar[3] == 0)) { | |
538 | dchar = xchar = rdBootVar[2]; /* Get the actual device */ | |
539 | if((xchar >= '0') && (xchar <= '9')) xchar = xchar - '0'; /* If digit, convert */ | |
540 | else { | |
541 | xchar = xchar & ~' '; /* Fold to upper case */ | |
542 | if((xchar >= 'A') && (xchar <= 'F')) { /* Is this a valid digit? */ | |
543 | xchar = (xchar & 0xF) + 9; /* Convert the hex digit */ | |
544 | dchar = dchar | ' '; /* Fold to lower case */ | |
545 | } | |
546 | else xchar = -1; /* Show bogus */ | |
547 | } | |
548 | if(xchar >= 0) { /* Do we have a valid memory device name? */ | |
549 | *root = mdevlookup(xchar); /* Find the device number */ | |
550 | if(*root >= 0) { /* Did we find one? */ | |
551 | ||
552 | rootName[0] = 'm'; /* Build root name */ | |
553 | rootName[1] = 'd'; /* Build root name */ | |
554 | rootName[2] = dchar; /* Build root name */ | |
555 | rootName[3] = 0; /* Build root name */ | |
556 | IOLog("BSD root: %s, major %d, minor %d\n", rootName, major(*root), minor(*root)); | |
557 | *oflags = 0; /* Show that this is not network */ | |
558 | goto iofrootx; /* Join common exit... */ | |
559 | } | |
560 | panic("IOFindBSDRoot: specified root memory device, %s, has not been configured\n", rdBootVar); /* Not there */ | |
561 | } | |
562 | } | |
563 | ||
1c79356b A |
564 | if( look) { |
565 | // from OpenFirmware path | |
566 | IOLog("From path: \"%s\", ", look); | |
567 | ||
0b4e3aa0 A |
568 | if( forceNet || (0 == strncmp( look, "enet", strlen( "enet" ))) ) { |
569 | matching = IONetworkMatching( look, str, kMaxPathBuf ); | |
570 | } else { | |
1c79356b | 571 | matching = IODiskMatching( look, str, kMaxPathBuf ); |
0b4e3aa0 | 572 | } |
1c79356b | 573 | } |
55e303ae A |
574 | |
575 | if( (!matching) && rdBootVar[0] ) { | |
1c79356b A |
576 | // by BSD name |
577 | look = rdBootVar; | |
578 | if( look[0] == '*') | |
579 | look++; | |
580 | ||
0b4e3aa0 A |
581 | if ( strncmp( look, "en", strlen( "en" )) == 0 ) { |
582 | matching = IONetworkNamePrefixMatching( "en" ); | |
55e303ae A |
583 | } else if ( strncmp( look, "cdrom", strlen( "cdrom" )) == 0 ) { |
584 | matching = IOCDMatching(); | |
585 | findHFSChild = true; | |
91447636 A |
586 | } else if ( strncmp( look, "uuid", strlen( "uuid" )) == 0 ) { |
587 | char *uuid; | |
588 | OSString *uuidString; | |
589 | ||
590 | uuid = (char *)IOMalloc( kMaxBootVar ); | |
591 | ||
592 | if ( uuid ) { | |
593 | if (!PE_parse_boot_arg( "boot-uuid", uuid )) { | |
594 | panic( "rd=uuid but no boot-uuid=<value> specified" ); | |
595 | } | |
596 | uuidString = OSString::withCString( uuid ); | |
597 | if ( uuidString ) { | |
598 | IOService::publishResource( "boot-uuid", uuidString ); | |
599 | uuidString->release(); | |
600 | IOLog( "\nWaiting for boot volume with UUID %s\n", uuid ); | |
601 | matching = IOUUIDMatching(); | |
602 | mediaProperty = "boot-uuid-media"; | |
603 | } | |
604 | IOFree( uuid, kMaxBootVar ); | |
605 | } | |
0b4e3aa0 A |
606 | } else { |
607 | matching = IOBSDNameMatching( look ); | |
608 | } | |
1c79356b A |
609 | } |
610 | ||
611 | if( !matching) { | |
612 | OSString * astring; | |
55e303ae | 613 | // any HFS |
1c79356b | 614 | matching = IOService::serviceMatching( "IOMedia" ); |
55e303ae | 615 | astring = OSString::withCStringNoCopy("Apple_HFS"); |
1c79356b | 616 | if ( astring ) { |
0b4e3aa0 | 617 | matching->setObject("Content", astring); |
1c79356b A |
618 | astring->release(); |
619 | } | |
620 | } | |
621 | ||
622 | if( true && matching) { | |
623 | OSSerialize * s = OSSerialize::withCapacity( 5 ); | |
624 | ||
625 | if( matching->serialize( s )) { | |
626 | IOLog( "Waiting on %s\n", s->text() ); | |
627 | s->release(); | |
628 | } | |
629 | } | |
630 | ||
1c79356b A |
631 | do { |
632 | t.tv_sec = ROOTDEVICETIMEOUT; | |
633 | t.tv_nsec = 0; | |
634 | matching->retain(); | |
635 | service = IOService::waitForService( matching, &t ); | |
636 | if( (!service) || (mountAttempts == 10)) { | |
637 | PE_display_icon( 0, "noroot"); | |
638 | IOLog( "Still waiting for root device\n" ); | |
0b4e3aa0 A |
639 | |
640 | if( !debugInfoPrintedOnce) { | |
641 | debugInfoPrintedOnce = true; | |
642 | if( gIOKitDebug & kIOLogDTree) { | |
643 | IOLog("\nDT plane:\n"); | |
644 | IOPrintPlane( gIODTPlane ); | |
645 | } | |
646 | if( gIOKitDebug & kIOLogServiceTree) { | |
647 | IOLog("\nService plane:\n"); | |
648 | IOPrintPlane( gIOServicePlane ); | |
649 | } | |
650 | if( gIOKitDebug & kIOLogMemory) | |
651 | IOPrintMemory(); | |
652 | } | |
1c79356b A |
653 | } |
654 | } while( !service); | |
655 | matching->release(); | |
656 | ||
55e303ae A |
657 | if ( service && findHFSChild ) { |
658 | bool waiting = true; | |
659 | // wait for children services to finish registering | |
660 | while ( waiting ) { | |
661 | t.tv_sec = ROOTDEVICETIMEOUT; | |
662 | t.tv_nsec = 0; | |
663 | if ( service->waitQuiet( &t ) == kIOReturnSuccess ) { | |
664 | waiting = false; | |
665 | } else { | |
666 | IOLog( "Waiting for child registration\n" ); | |
667 | } | |
668 | } | |
669 | // look for a subservice with an Apple_HFS child | |
670 | IOService * subservice = IOFindMatchingChild( service ); | |
671 | if ( subservice ) service = subservice; | |
91447636 A |
672 | } else if ( service && mediaProperty ) { |
673 | service = service->getProperty(mediaProperty); | |
55e303ae A |
674 | } |
675 | ||
1c79356b A |
676 | major = 0; |
677 | minor = 0; | |
678 | ||
679 | // If the IOService we matched to is a subclass of IONetworkInterface, | |
680 | // then make sure it has been registered with BSD and has a BSD name | |
681 | // assigned. | |
682 | ||
683 | if ( service | |
684 | && service->metaCast( "IONetworkInterface" ) | |
0b4e3aa0 | 685 | && !IORegisterNetworkInterface( service ) ) |
1c79356b A |
686 | { |
687 | service = 0; | |
688 | } | |
1c79356b A |
689 | |
690 | if( service) { | |
691 | ||
692 | len = kMaxPathBuf; | |
693 | service->getPath( str, &len, gIOServicePlane ); | |
694 | IOLog( "Got boot device = %s\n", str ); | |
695 | ||
696 | iostr = (OSString *) service->getProperty( kIOBSDNameKey ); | |
697 | if( iostr) | |
698 | strcpy( rootName, iostr->getCStringNoCopy() ); | |
699 | off = (OSNumber *) service->getProperty( kIOBSDMajorKey ); | |
700 | if( off) | |
701 | major = off->unsigned32BitValue(); | |
702 | off = (OSNumber *) service->getProperty( kIOBSDMinorKey ); | |
703 | if( off) | |
704 | minor = off->unsigned32BitValue(); | |
705 | ||
706 | if( service->metaCast( "IONetworkInterface" )) | |
707 | flags |= 1; | |
708 | ||
709 | } else { | |
710 | ||
711 | IOLog( "Wait for root failed\n" ); | |
712 | strcpy( rootName, "en0"); | |
713 | flags |= 1; | |
714 | } | |
715 | ||
716 | IOLog( "BSD root: %s", rootName ); | |
717 | if( major) | |
718 | IOLog(", major %d, minor %d\n", major, minor ); | |
719 | else | |
720 | IOLog("\n"); | |
721 | ||
722 | *root = makedev( major, minor ); | |
723 | *oflags = flags; | |
724 | ||
725 | IOFree( str, kMaxPathBuf + kMaxBootVar ); | |
726 | ||
55e303ae | 727 | iofrootx: |
0b4e3aa0 | 728 | if( (gIOKitDebug & (kIOLogDTree | kIOLogServiceTree | kIOLogMemory)) && !debugInfoPrintedOnce) { |
1c79356b | 729 | |
0b4e3aa0 | 730 | IOService::getPlatform()->waitQuiet(); |
1c79356b A |
731 | if( gIOKitDebug & kIOLogDTree) { |
732 | IOLog("\nDT plane:\n"); | |
733 | IOPrintPlane( gIODTPlane ); | |
734 | } | |
735 | if( gIOKitDebug & kIOLogServiceTree) { | |
736 | IOLog("\nService plane:\n"); | |
737 | IOPrintPlane( gIOServicePlane ); | |
738 | } | |
739 | if( gIOKitDebug & kIOLogMemory) | |
740 | IOPrintMemory(); | |
741 | } | |
742 | ||
743 | return( kIOReturnSuccess ); | |
744 | } | |
745 | ||
9bccf70c A |
746 | void * |
747 | IOBSDRegistryEntryForDeviceTree(char * path) | |
748 | { | |
749 | return (IORegistryEntry::fromPath(path, gIODTPlane)); | |
750 | } | |
751 | ||
752 | void | |
753 | IOBSDRegistryEntryRelease(void * entry) | |
754 | { | |
755 | IORegistryEntry * regEntry = (IORegistryEntry *)entry; | |
756 | ||
757 | if (regEntry) | |
758 | regEntry->release(); | |
759 | return; | |
760 | } | |
761 | ||
762 | const void * | |
763 | IOBSDRegistryEntryGetData(void * entry, char * property_name, | |
764 | int * packet_length) | |
765 | { | |
766 | OSData * data; | |
767 | IORegistryEntry * regEntry = (IORegistryEntry *)entry; | |
768 | ||
769 | data = (OSData *) regEntry->getProperty(property_name); | |
770 | if (data) { | |
771 | *packet_length = data->getLength(); | |
772 | return (data->getBytesNoCopy()); | |
773 | } | |
774 | return (NULL); | |
775 | } | |
776 | ||
1c79356b | 777 | } /* extern "C" */ |