autoconf.c revision 1.2 1 1.2 cgd /* $NetBSD: autoconf.c,v 1.2 1996/04/04 06:25:00 cgd Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.1 cgd * Copyright (c) 1994, 1995 Carnegie-Mellon University.
5 1.1 cgd * All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Authors: Keith Bostic, Chris G. Demetriou
8 1.1 cgd *
9 1.1 cgd * Permission to use, copy, modify and distribute this software and
10 1.1 cgd * its documentation is hereby granted, provided that both the copyright
11 1.1 cgd * notice and this permission notice appear in all copies of the
12 1.1 cgd * software, derivative works or modified versions, and any portions
13 1.1 cgd * thereof, and that both notices appear in supporting documentation.
14 1.1 cgd *
15 1.1 cgd * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 cgd * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 cgd * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 cgd *
19 1.1 cgd * Carnegie Mellon requests users of this software to return to
20 1.1 cgd *
21 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 cgd * School of Computer Science
23 1.1 cgd * Carnegie Mellon University
24 1.1 cgd * Pittsburgh PA 15213-3890
25 1.1 cgd *
26 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
27 1.1 cgd * rights to redistribute these changes.
28 1.1 cgd */
29 1.1 cgd
30 1.1 cgd #include <sys/param.h>
31 1.1 cgd #include <sys/systm.h>
32 1.1 cgd #include <sys/buf.h>
33 1.1 cgd #include <sys/disklabel.h>
34 1.1 cgd #include <sys/conf.h>
35 1.1 cgd #include <sys/reboot.h>
36 1.1 cgd #include <sys/device.h>
37 1.1 cgd
38 1.1 cgd #include <machine/autoconf.h>
39 1.1 cgd
40 1.1 cgd /*
41 1.1 cgd * configure:
42 1.1 cgd * called at boot time, configure all devices on system
43 1.1 cgd */
44 1.1 cgd void
45 1.1 cgd configure()
46 1.1 cgd {
47 1.1 cgd extern int cold;
48 1.1 cgd
49 1.1 cgd (void)splhigh();
50 1.2 cgd if (config_rootfound("mainbus", "mainbus") == NULL)
51 1.1 cgd panic("no mainbus found");
52 1.1 cgd (void)spl0();
53 1.1 cgd
54 1.1 cgd #ifdef GENERIC
55 1.1 cgd if ((boothowto & RB_ASKNAME) == 0)
56 1.1 cgd setroot();
57 1.1 cgd setconf();
58 1.1 cgd #else
59 1.1 cgd setroot();
60 1.1 cgd #endif
61 1.1 cgd swapconf();
62 1.1 cgd cold = 0;
63 1.1 cgd }
64 1.1 cgd
65 1.1 cgd /*
66 1.1 cgd * Configure swap space and related parameters.
67 1.1 cgd */
68 1.1 cgd swapconf()
69 1.1 cgd {
70 1.1 cgd register struct swdevt *swp;
71 1.1 cgd register int nblks;
72 1.1 cgd
73 1.1 cgd for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
74 1.1 cgd int maj = major(swp->sw_dev);
75 1.1 cgd
76 1.1 cgd if (maj > nblkdev)
77 1.1 cgd break;
78 1.1 cgd if (bdevsw[maj].d_psize) {
79 1.1 cgd nblks = (*bdevsw[maj].d_psize)(swp->sw_dev);
80 1.1 cgd if (nblks != -1 &&
81 1.1 cgd (swp->sw_nblks == 0 || swp->sw_nblks > nblks))
82 1.1 cgd swp->sw_nblks = nblks;
83 1.1 cgd swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
84 1.1 cgd }
85 1.1 cgd }
86 1.1 cgd }
87 1.1 cgd
88 1.1 cgd #define DOSWAP /* change swdevt and dumpdev */
89 1.1 cgd dev_t bootdev = 0; /* should be dev_t, but not until 32 bits */
90 1.1 cgd
91 1.1 cgd static char devname[][2] = {
92 1.1 cgd 'x','x', /* 0 = XX */
93 1.1 cgd 'x','x', /* 1 = XX */
94 1.1 cgd 'x','x', /* 2 = XX */
95 1.1 cgd 'x','x', /* 3 = XX */
96 1.1 cgd 'x','x', /* 4 = XX */
97 1.1 cgd 'x','x', /* 5 = XX */
98 1.1 cgd 'x','x', /* 6 = XX */
99 1.1 cgd 'x','x', /* 7 = XX */
100 1.1 cgd 's','d', /* 8 = sd */
101 1.1 cgd };
102 1.1 cgd
103 1.1 cgd /*
104 1.1 cgd * Attempt to find the device from which we were booted.
105 1.1 cgd * If we can do so, and not instructed not to do so,
106 1.1 cgd * change rootdev to correspond to the load device.
107 1.1 cgd */
108 1.1 cgd setroot()
109 1.1 cgd {
110 1.1 cgd int majdev, mindev, unit, part, adaptor;
111 1.1 cgd dev_t temp, orootdev;
112 1.1 cgd struct swdevt *swp;
113 1.1 cgd
114 1.1 cgd /*printf("howto %x bootdev %x ", boothowto, bootdev);*/
115 1.1 cgd if (boothowto & RB_DFLTROOT ||
116 1.1 cgd (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
117 1.1 cgd return;
118 1.1 cgd majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK;
119 1.1 cgd if (majdev > sizeof(devname) / sizeof(devname[0]))
120 1.1 cgd return;
121 1.1 cgd adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK;
122 1.1 cgd part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
123 1.1 cgd unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
124 1.1 cgd mindev = (unit * MAXPARTITIONS) + part;
125 1.1 cgd orootdev = rootdev;
126 1.1 cgd rootdev = makedev(majdev, mindev);
127 1.1 cgd /*
128 1.1 cgd * If the original rootdev is the same as the one
129 1.1 cgd * just calculated, don't need to adjust the swap configuration.
130 1.1 cgd */
131 1.1 cgd if (rootdev == orootdev)
132 1.1 cgd return;
133 1.1 cgd printf("changing root device to %c%c%d%c\n",
134 1.1 cgd devname[majdev][0], devname[majdev][1],
135 1.1 cgd unit, part + 'a');
136 1.1 cgd
137 1.1 cgd #ifdef DOSWAP
138 1.1 cgd for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
139 1.1 cgd if (majdev == major(swp->sw_dev) &&
140 1.1 cgd (mindev / MAXPARTITIONS)
141 1.1 cgd == (minor(swp->sw_dev) / MAXPARTITIONS)) {
142 1.1 cgd temp = swdevt[0].sw_dev;
143 1.1 cgd swdevt[0].sw_dev = swp->sw_dev;
144 1.1 cgd swp->sw_dev = temp;
145 1.1 cgd break;
146 1.1 cgd }
147 1.1 cgd }
148 1.1 cgd if (swp->sw_dev == NODEV)
149 1.1 cgd return;
150 1.1 cgd
151 1.1 cgd /*
152 1.1 cgd * If dumpdev was the same as the old primary swap device, move
153 1.1 cgd * it to the new primary swap device.
154 1.1 cgd */
155 1.1 cgd if (temp == dumpdev)
156 1.1 cgd dumpdev = swdevt[0].sw_dev;
157 1.1 cgd #endif
158 1.1 cgd }
159