1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
/* $OpenBSD: autoconf.c,v 1.12 2001/06/24 04:49:27 drahn Exp $ */
/*
* Copyright (c) 1996, 1997 Per Fogelstrom
* Copyright (c) 1995 Theo de Raadt
* Copyright (c) 1988 University of Utah.
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department and Ralph Campbell.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Utah Hdr: autoconf.c 1.31 91/01/21
*
* from: @(#)autoconf.c 8.1 (Berkeley) 6/10/93
* $Id: autoconf.c,v 1.12 2001/06/24 04:49:27 drahn Exp $
*/
/*
* Setup the system to run on the current machine.
*
* cpu_configure() is called at boot time. Available
* devices are determined (from possibilities mentioned in ioconf.c),
* and the drivers are initialized.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/disklabel.h>
#include <sys/conf.h>
#include <sys/reboot.h>
#include <sys/device.h>
#include <machine/autoconf.h>
struct device *parsedisk __P((char *, int, int, dev_t *));
void setroot __P((void));
void swapconf __P((void));
extern void dumpconf __P((void));
static int findblkmajor __P((struct device *));
static struct device * getdisk __P((char *, int, int, dev_t *));
struct device * getdevunit __P((char *, int));
static struct devmap * findtype __P((char **));
void makebootdev __P((char *cp));
int getpno __P((char **));
void diskconf(void);
/*
* The following several variables are related to
* the configuration process, and are used in initializing
* the machine.
*/
int cold = 1; /* if 1, still working on cold-start */
char bootdev[16]; /* to hold boot dev name */
struct device *bootdv = NULL;
/*
* Configure all devices found that we know about.
* This is done at boot time.
*/
void
cpu_configure()
{
(void)splhigh(); /* To be really sure.. */
calc_delayconst();
/*
if(system_type == OFWMACH) {
ofrootfound();
}
*/
if(config_rootfound("mainbus", "mainbus") == 0)
panic("no mainbus found");
(void)spl0();
/*
* We can not know which is our root disk, defer
* until we can checksum blocks to figure it out.
*/
md_diskconf = diskconf;
cold = 0;
}
/*
* Now that we are fully operational, we can checksum the
* disks, and using some heuristics, hopefully are able to
* always determine the correct root disk.
*/
void
diskconf()
{
/*
* Configure root, swap, and dump area. This is
* currently done by running the same checksum
* algorithm over all known disks, as was done in
* /boot. Then we basically fixup the *dev vars
* from the info we gleaned from this.
dkcsumattach();
* - XXX
*/
#if 0
rootconf();
#endif
setroot();
swapconf();
#if 0
dumpconf();
#endif
}
/*
* Configure swap space and related parameters.
*/
void
swapconf()
{
register struct swdevt *swp;
register int nblks;
for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
if (bdevsw[major(swp->sw_dev)].d_psize) {
nblks =
(*bdevsw[major(swp->sw_dev)].d_psize)(swp->sw_dev);
if (nblks != -1 &&
(swp->sw_nblks == 0 || swp->sw_nblks > nblks))
swp->sw_nblks = nblks;
swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
}
}
#if 0
dumpconf();
#endif
}
/*
* Crash dump handling.
*/
u_long dumpmag = 0x8fca0101; /* magic number */
int dumpsize = 0; /* size of dump in pages */
long dumplo = -1; /* blocks */
/*
* This is called by configure to set dumplo and dumpsize.
* Dumps always skip the first CLBYTES of disk space
* in case there might be a disk label stored there.
* If there is extra space, put dump at the end to
* reduce the chance that swapping trashes it.
*/
#if 0
void
dumpconf()
{
int nblks; /* size of dump area */
int maj;
if (dumpdev == NODEV)
return;
maj = major(dumpdev);
if (maj < 0 || maj >= nblkdev)
panic("dumpconf: bad dumpdev=0x%x", dumpdev);
if (bdevsw[maj].d_psize == NULL)
return;
nblks = (*bdevsw[maj].d_psize)(dumpdev);
if (nblks <= ctod(1))
return;
dumpsize = btoc(IOM_END + ctob(dumpmem_high));
/* Always skip the first CLBYTES, in case there is a label there. */
if (dumplo < ctod(1))
dumplo = ctod(1);
/* Put dump at end of partition, and make it fit. */
if (dumpsize > dtoc(nblks - dumplo))
dumpsize = dtoc(nblks - dumplo);
if (dumplo < nblks - ctod(dumpsize))
dumplo = nblks - ctod(dumpsize);
}
#endif
static struct nam2blk {
char *name;
int maj;
} nam2blk[] = {
{ "wd", 0 }, /* 0 = wd */
{ "sd", 2 }, /* 2 = sd */
{ "ofdisk", 4 }, /* 4 = ofdisk */
};
static int
findblkmajor(dv)
struct device *dv;
{
char *name = dv->dv_xname;
register int i;
for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); ++i)
if (strncmp(name, nam2blk[i].name, strlen(nam2blk[0].name)) == 0)
return (nam2blk[i].maj);
return (-1);
}
static struct device *
getdisk(str, len, defpart, devp)
char *str;
int len, defpart;
dev_t *devp;
{
register struct device *dv;
if ((dv = parsedisk(str, len, defpart, devp)) == NULL) {
printf("use one of:");
for (dv = alldevs.tqh_first; dv != NULL;
dv = dv->dv_list.tqe_next) {
if (dv->dv_class == DV_DISK)
printf(" %s[a-h]", dv->dv_xname);
#ifdef NFSCLIENT
if (dv->dv_class == DV_IFNET)
printf(" %s", dv->dv_xname);
#endif
}
printf("\n");
}
return (dv);
}
struct device *
parsedisk(str, len, defpart, devp)
char *str;
int len, defpart;
dev_t *devp;
{
register struct device *dv;
register char *cp, c;
int majdev, part;
if (len == 0)
return (NULL);
cp = str + len - 1;
c = *cp;
if (c >= 'a' && (c - 'a') < MAXPARTITIONS) {
part = c - 'a';
*cp = '\0';
} else
part = defpart;
for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
if (dv->dv_class == DV_DISK &&
strcmp(str, dv->dv_xname) == 0) {
majdev = findblkmajor(dv);
if (majdev < 0)
panic("parsedisk");
*devp = MAKEDISKDEV(majdev, dv->dv_unit, part);
break;
}
#ifdef NFSCLIENT
if (dv->dv_class == DV_IFNET &&
strcmp(str, dv->dv_xname) == 0) {
*devp = NODEV;
break;
}
#endif
}
*cp = c;
return (dv);
}
/*
* Attempt to find the device from which we were booted.
* If we can do so, and not instructed not to do so,
* change rootdev to correspond to the load device.
*/
void
setroot()
{
int majdev, mindev, unit, part, len;
dev_t temp;
struct swdevt *swp;
struct device *dv;
dev_t nrootdev, nswapdev = NODEV;
char buf[128];
#if defined(NFSCLIENT)
extern char *nfsbootdevname;
#endif
printf("bootpath: '%s'\n", bootpath);
makebootdev(bootpath);
if(boothowto & RB_DFLTROOT)
return; /* Boot compiled in */
/* Lookup boot device from boot if not set by configuration */
if(bootdv == NULL) {
bootdv = parsedisk(bootdev, strlen(bootdev), 0, &temp);
}
if(bootdv == NULL) {
printf("boot device: lookup '%s' failed.\n", bootdev);
boothowto |= RB_ASKNAME; /* Don't Panic :-) */
/* boothowto |= RB_SINGLE; */
}
else {
printf("boot device: %s.\n", bootdv->dv_xname);
}
if (boothowto & RB_ASKNAME) {
for (;;) {
printf("root device ");
if (bootdv != NULL)
printf("(default %s%c)",
bootdv->dv_xname,
bootdv->dv_class == DV_DISK
? 'a' : ' ');
printf(": ");
len = getsn(buf, sizeof(buf));
if (len == 0 && bootdv != NULL) {
strcpy(buf, bootdv->dv_xname);
len = strlen(buf);
}
if (len > 0 && buf[len - 1] == '*') {
buf[--len] = '\0';
dv = getdisk(buf, len, 1, &nrootdev);
if (dv != NULL) {
bootdv = dv;
nswapdev = nrootdev;
goto gotswap;
}
}
dv = getdisk(buf, len, 0, &nrootdev);
if (dv != NULL) {
bootdv = dv;
break;
}
}
/*
* because swap must be on same device as root, for
* network devices this is easy.
*/
if (bootdv->dv_class == DV_IFNET) {
goto gotswap;
}
for (;;) {
printf("swap device ");
if (bootdv != NULL)
printf("(default %s%c)",
bootdv->dv_xname,
bootdv->dv_class == DV_DISK?'b':' ');
printf(": ");
len = getsn(buf, sizeof(buf));
if (len == 0 && bootdv != NULL) {
switch (bootdv->dv_class) {
case DV_IFNET:
nswapdev = NODEV;
break;
case DV_DISK:
nswapdev = MAKEDISKDEV(major(nrootdev),
DISKUNIT(nrootdev), 1);
break;
case DV_TAPE:
case DV_TTY:
case DV_DULL:
case DV_CPU:
break;
}
break;
}
dv = getdisk(buf, len, 1, &nswapdev);
if (dv) {
if (dv->dv_class == DV_IFNET)
nswapdev = NODEV;
break;
}
}
gotswap:
rootdev = nrootdev;
dumpdev = nswapdev;
swdevt[0].sw_dev = nswapdev;
swdevt[1].sw_dev = NODEV;
}
else if(mountroot == NULL) {
/*
* `swap generic': Use the device the ROM told us to use.
*/
if (bootdv == NULL)
panic("boot device not known");
majdev = findblkmajor(bootdv);
if (majdev >= 0) {
/*
* Root and Swap are on disk.
* Boot is always from partition 0.
*/
rootdev = MAKEDISKDEV(majdev, bootdv->dv_unit, 0);
nswapdev = MAKEDISKDEV(majdev, bootdv->dv_unit, 1);
dumpdev = nswapdev;
}
else {
/*
* Root and Swap are on net.
*/
nswapdev = dumpdev = NODEV;
}
swdevt[0].sw_dev = nswapdev;
swdevt[1].sw_dev = NODEV;
} else {
/*
* `root DEV swap DEV': honour rootdev/swdevt.
* rootdev/swdevt/mountroot already properly set.
*/
return;
}
switch (bootdv->dv_class) {
#if defined(NFSCLIENT)
case DV_IFNET:
mountroot = nfs_mountroot;
nfsbootdevname = bootdv->dv_xname;
return;
#endif
case DV_DISK:
mountroot = dk_mountroot;
majdev = major(rootdev);
mindev = minor(rootdev);
unit = DISKUNIT(rootdev);
part = DISKPART(rootdev);
printf("root on %s%c\n", bootdv->dv_xname, part + 'a');
break;
default:
printf("can't figure root, hope your kernel is right\n");
return;
}
/*
* XXX: What is this doing?
*/
temp = NODEV;
for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
if (majdev == major(swp->sw_dev) &&
unit == DISKUNIT(swp->sw_dev)) {
temp = swdevt[0].sw_dev;
swdevt[0].sw_dev = swp->sw_dev;
swp->sw_dev = temp;
break;
}
}
if (swp->sw_dev == NODEV)
return;
/*
* If dumpdev was the same as the old primary swap device, move
* it to the new primary swap device.
*/
if (temp == dumpdev)
dumpdev = swdevt[0].sw_dev;
}
/*
* find a device matching "name" and unit number
*/
struct device *
getdevunit(name, unit)
char *name;
int unit;
{
struct device *dev = alldevs.tqh_first;
char num[10], fullname[16];
int lunit;
/* compute length of name and decimal expansion of unit number */
sprintf(num, "%d", unit);
lunit = strlen(num);
if (strlen(name) + lunit >= sizeof(fullname) - 1)
panic("config_attach: device name too long");
strcpy(fullname, name);
strcat(fullname, num);
while (strcmp(dev->dv_xname, fullname) != 0) {
if ((dev = dev->dv_list.tqe_next) == NULL)
return NULL;
}
return dev;
}
struct devmap {
char *att;
char *dev;
int type;
};
#define T_IFACE 0x10
#define T_BUS 0x00
#define T_SCSI 0x11
#define T_IDE 0x12
#define T_DISK 0x21
static struct devmap *
findtype(s)
char **s;
{
static struct devmap devmap[] = {
{ "/pci@", NULL, T_BUS },
{ "/pci", NULL, T_BUS },
{ "/mac-io@", NULL, T_BUS },
{ "/mac-io", NULL, T_BUS },
{ "/@", NULL, T_BUS },
{ "/scsi@", "sd", T_SCSI },
{ "/ide", "wd", T_IDE },
{ "/ata", "wd", T_IDE },
{ "/disk@", "sd", T_DISK },
{ "/disk", "wd", T_DISK },
{ NULL, NULL }
};
struct devmap *dp = &devmap[0];
while (dp->att) {
if (strncmp (*s, dp->att, strlen(dp->att)) == 0) {
*s += strlen(dp->att);
break;
}
dp++;
}
if (dp->att == NULL) {
printf("string [%s]not found\n", *s);
}
return(dp);
}
/*
* Look at the string 'bp' and decode the boot device.
* Boot names look like: '/pci/scsi@c/disk@0,0/bsd'
* '/pci/mac-io/ide@20000/disk@0,0/bsd
* '/pci/mac-io/ide/disk/bsd
*/
void
makebootdev(bp)
char *bp;
{
int unit;
char *dev, *cp;
struct devmap *dp;
cp = bp;
do {
while(*cp && *cp != '/') {
cp++;
}
dp = findtype(&cp);
if (!dp->att) {
printf("Warning: boot device unrecognized: %s\n", bp);
return;
}
} while((dp->type & T_IFACE) == 0);
dev = dp->dev;
while(*cp && *cp != '/')
cp++;
dp = findtype(&cp);
if (!dp->att || dp->type != T_DISK) {
printf("Warning: boot device unrecognized: %s\n", bp);
return;
}
unit = getpno(&cp);
sprintf(bootdev, "%s%d%c", dev, unit, 'a');
}
int
getpno(cp)
char **cp;
{
int val = 0;
char *cx = *cp;
while(*cx && *cx >= '0' && *cx <= '9') {
val = val * 10 + *cx - '0';
cx++;
}
*cp = cx;
return val;
}
|