Annotation of src/sys/arch/zaurus/zaurus/autoconf.c, Revision 1.10.10.2
1.10.10.1 riz 1: /* $NetBSD$ */
1.1 ober 2:
3: /*-
4: * Copyright (c) 2002 The NetBSD Foundation, Inc.
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: *
16: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26: * POSSIBILITY OF SUCH DAMAGE.
27: */
28:
29: #include <sys/cdefs.h>
1.10.10.1 riz 30: __KERNEL_RCSID(0, "$NetBSD$");
1.1 ober 31:
1.2 peter 32: #include "opt_md.h"
33:
1.1 ober 34: #include <sys/param.h>
35: #include <sys/systm.h>
1.7 nonaka 36: #include <sys/device.h>
1.2 peter 37: #include <sys/disklabel.h>
1.1 ober 38: #include <sys/conf.h>
1.2 peter 39: #include <sys/malloc.h>
1.7 nonaka 40: #include <sys/vnode.h>
41: #include <sys/fcntl.h>
42: #include <sys/proc.h>
43: #include <sys/disk.h>
44: #include <sys/kauth.h>
1.2 peter 45:
46: #include <machine/intr.h>
47: #include <machine/bootconfig.h>
1.7 nonaka 48: #include <machine/bootinfo.h>
1.3 nonaka 49: #include <machine/config_hook.h>
1.2 peter 50:
1.9 dyoung 51: static int is_valid_disk(device_t dv);
52: static int match_bootdisk(device_t dv, struct btinfo_bootdisk *bid);
1.7 nonaka 53: static void findroot(void);
1.1 ober 54:
55: void
56: cpu_configure(void)
57: {
58:
59: splhigh();
1.2 peter 60: splserial();
61:
1.3 nonaka 62: config_hook_init();
63:
1.1 ober 64: if (config_rootfound("mainbus", NULL) == NULL)
65: panic("no mainbus found");
66:
67: /* Configuration is finished, turn on interrupts. */
68: spl0();
69: }
70:
1.7 nonaka 71: static int
1.9 dyoung 72: is_valid_disk(device_t dv)
1.7 nonaka 73: {
74:
75: if (device_class(dv) != DV_DISK)
76: return 0;
77:
78: return (device_is_a(dv, "dk") ||
79: device_is_a(dv, "sd") ||
80: device_is_a(dv, "wd") ||
81: device_is_a(dv, "ld"));
82: }
83:
84: /*
85: * Helper function for findroot():
86: * Return non-zero if disk device matches bootinfo.
87: */
88: static int
1.9 dyoung 89: match_bootdisk(device_t dv, struct btinfo_bootdisk *bid)
1.7 nonaka 90: {
91: struct vnode *tmpvn;
92: int error;
93: struct disklabel label;
94: int found = 0;
95:
96: if (device_is_a(dv, "dk"))
97: return 0;
98:
99: /*
100: * A disklabel is required here. The boot loader doesn't refuse
101: * to boot from a disk without a label, but this is normally not
102: * wanted.
103: */
104: if (bid->labelsector == -1)
105: return 0;
106:
107: if ((tmpvn = opendisk(dv)) == NULL)
108: return 0;
109:
110: error = VOP_IOCTL(tmpvn, DIOCGDINFO, &label, FREAD, NOCRED);
111: if (error) {
112: /*
113: * XXX Can't happen -- open() would have errored out
114: * or faked one up.
115: */
116: printf("match_bootdisk: can't get label for dev %s (%d)\n",
117: device_xname(dv), error);
118: goto closeout;
119: }
120:
121: /* Compare with our data. */
122: if (label.d_type == bid->label.type &&
123: label.d_checksum == bid->label.checksum &&
124: strncmp(label.d_packname, bid->label.packname, 16) == 0)
125: found = 1;
126:
127: closeout:
128: VOP_CLOSE(tmpvn, FREAD, NOCRED);
129: vput(tmpvn);
130: return found;
131: }
132:
133: static void
134: findroot(void)
135: {
1.8 nonaka 136: struct btinfo_rootdevice *biv;
1.7 nonaka 137: struct btinfo_bootdisk *bid;
138: device_t dv;
1.9 dyoung 139: deviter_t di;
1.7 nonaka 140:
141: if (booted_device)
142: return;
143:
1.8 nonaka 144: if ((biv = lookup_bootinfo(BTINFO_ROOTDEVICE)) != NULL) {
1.9 dyoung 145: for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
146: dv != NULL;
147: dv = deviter_next(&di)) {
1.8 nonaka 148: cfdata_t cd;
149: size_t len;
150:
151: if (device_class(dv) != DV_DISK)
152: continue;
153:
154: cd = device_cfdata(dv);
155: len = strlen(cd->cf_name);
156:
157: if (strncmp(cd->cf_name, biv->devname, len) == 0 &&
158: biv->devname[len] - '0' == cd->cf_unit) {
1.10.10.1 riz 159: booted_device = dv;
160: booted_partition = biv->devname[len + 1] - 'a';
1.9 dyoung 161: break;
1.8 nonaka 162: }
163: }
1.9 dyoung 164: deviter_release(&di);
165: if (dv != NULL)
166: return;
1.8 nonaka 167: }
168:
1.7 nonaka 169: if ((bid = lookup_bootinfo(BTINFO_BOOTDISK)) != NULL) {
170: /*
171: * Scan all disk devices for ones that match the passed data.
172: * Don't break if one is found, to get possible multiple
173: * matches - for problem tracking. Use the first match anyway
174: * because lower device numbers are more likely to be the
175: * boot device.
176: */
1.9 dyoung 177: for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
178: dv != NULL;
179: dv = deviter_next(&di)) {
1.7 nonaka 180: if (device_class(dv) != DV_DISK)
181: continue;
182:
183: if (is_valid_disk(dv)) {
1.10 nonaka 184: if (match_bootdisk(dv, bid))
185: goto bootdisk_found;
1.7 nonaka 186: }
187: continue;
188:
189: bootdisk_found:
190: if (booted_device) {
191: printf("WARNING: double match for boot "
192: "device (%s, %s)\n",
193: device_xname(booted_device),
194: device_xname(dv));
195: continue;
196: }
1.10.10.1 riz 197: booted_device = dv;
198: booted_partition = bid->partition;
1.7 nonaka 199: }
1.9 dyoung 200: deviter_release(&di);
1.7 nonaka 201:
202: if (booted_device)
203: return;
204: }
205: }
206:
207: void
208: cpu_rootconf(void)
209: {
210:
211: findroot();
212:
213: aprint_normal("boot device: %s\n",
214: booted_device ? device_xname(booted_device) : "<unknown>");
1.10.10.2! martin 215: rootconf();
1.7 nonaka 216: }
217:
1.1 ober 218: void
1.9 dyoung 219: device_register(device_t dev, void *aux)
1.1 ober 220: {
221:
222: /* Nothing to do */
223: }
CVSweb <webmaster@jp.NetBSD.org>