dk.c revision 1.1 1 1.1 skrll /* $NetBSD: dk.c,v 1.1 2014/02/24 07:23:43 skrll Exp $ */
2 1.1 skrll
3 1.1 skrll /* $OpenBSD: dk.c,v 1.5 1999/04/20 20:01:01 mickey Exp $ */
4 1.1 skrll
5 1.1 skrll /*
6 1.1 skrll * Copyright 1996 1995 by Open Software Foundation, Inc.
7 1.1 skrll * All Rights Reserved
8 1.1 skrll *
9 1.1 skrll * Permission to use, copy, modify, and distribute this software and
10 1.1 skrll * its documentation for any purpose and without fee is hereby granted,
11 1.1 skrll * provided that the above copyright notice appears in all copies and
12 1.1 skrll * that both the copyright notice and this permission notice appear in
13 1.1 skrll * supporting documentation.
14 1.1 skrll *
15 1.1 skrll * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
16 1.1 skrll * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
17 1.1 skrll * FOR A PARTICULAR PURPOSE.
18 1.1 skrll *
19 1.1 skrll * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
20 1.1 skrll * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21 1.1 skrll * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
22 1.1 skrll * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
23 1.1 skrll * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 1.1 skrll *
25 1.1 skrll */
26 1.1 skrll
27 1.1 skrll #include "libsa.h"
28 1.1 skrll
29 1.1 skrll #include <sys/param.h>
30 1.1 skrll #include <sys/disklabel.h>
31 1.1 skrll #include <sys/reboot.h>
32 1.1 skrll #include <machine/pdc.h>
33 1.1 skrll #include <machine/iomod.h>
34 1.1 skrll
35 1.1 skrll #include "dev_hppa.h"
36 1.1 skrll
37 1.1 skrll const char *dk_disklabel(struct hppa_dev *, struct disklabel *);
38 1.1 skrll
39 1.1 skrll iodcio_t dkiodc; /* boot IODC entry point */
40 1.1 skrll
41 1.1 skrll const char *
42 1.1 skrll dk_disklabel(struct hppa_dev *dp, struct disklabel *label)
43 1.1 skrll {
44 1.1 skrll char buf[DEV_BSIZE];
45 1.1 skrll size_t ret;
46 1.1 skrll
47 1.1 skrll if (iodcstrategy(dp, F_READ, LABELSECTOR, DEV_BSIZE, buf, &ret) ||
48 1.1 skrll ret != DEV_BSIZE)
49 1.1 skrll return "can't read disklabel";
50 1.1 skrll
51 1.1 skrll return (getdisklabel(buf, label));
52 1.1 skrll }
53 1.1 skrll
54 1.1 skrll int
55 1.1 skrll dkopen(struct open_file *f, ...)
56 1.1 skrll {
57 1.1 skrll struct disklabel dkl;
58 1.1 skrll struct hppa_dev *dp = f->f_devdata;
59 1.1 skrll const char *st;
60 1.1 skrll u_int i;
61 1.1 skrll
62 1.1 skrll #ifdef DEBUG
63 1.1 skrll if (debug)
64 1.1 skrll printf("dkopen(%p)\n", f);
65 1.1 skrll #endif
66 1.1 skrll
67 1.1 skrll if (!(dp->pz_dev = pdc_findev(-1, PCL_RANDOM)))
68 1.1 skrll return ENXIO;
69 1.1 skrll
70 1.1 skrll dp->part_off = 0;
71 1.1 skrll st = NULL;
72 1.1 skrll #ifdef DEBUG
73 1.1 skrll if (debug)
74 1.1 skrll printf ("disklabel\n");
75 1.1 skrll #endif
76 1.1 skrll if ((st = dk_disklabel(dp, &dkl)) != NULL) {
77 1.1 skrll #ifdef DEBUG
78 1.1 skrll if (debug)
79 1.1 skrll printf ("dkopen: %s\n", st);
80 1.1 skrll #endif
81 1.1 skrll /*
82 1.1 skrll * Ignore disklabel errors for this two reasons:
83 1.1 skrll * 1. It is possible to dd(1) a LIF image containing the bootloader
84 1.1 skrll * and a kernel with attached RAM disk to disk and boot it. That way
85 1.1 skrll * the netboot installation LIF image is also usable as disk boot
86 1.1 skrll * image.
87 1.1 skrll * 2. Some old 700 machines report a wrong device class in
88 1.1 skrll * PAGE0->mem_boot.pz_class when net booting. (PCL_RANDOM instead
89 1.1 skrll * PCL_NET_MASK|PCL_SEQU) So the bootloader thinks it is booting
90 1.1 skrll * from disk when it is actually net booting. The net boot LIF image
91 1.1 skrll * contains no disklabel so the test for the disklabel will fail.
92 1.1 skrll * If the device open fails if there is no disklabel we are not able
93 1.1 skrll * to netboot those machines.
94 1.1 skrll * Therefore the error is ignored. The bootloader will fall back to
95 1.1 skrll * LIF later when there is no disklabel / FFS partition.
96 1.1 skrll * At the moment it doesn't matter that the wrong device type ("dk"
97 1.1 skrll * instead "lf") is used, as all I/O is abstracted by the firmware.
98 1.1 skrll * To get the correct device type it would be necessary to add a
99 1.1 skrll * quirk table to the switch() in dev_hppa.c:devboot().
100 1.1 skrll */
101 1.1 skrll } else {
102 1.1 skrll i = B_PARTITION(dp->bootdev);
103 1.1 skrll #ifdef DEBUG
104 1.1 skrll if (debug)
105 1.1 skrll printf("bootdev 0x%x, partition %u\n", dp->bootdev, i);
106 1.1 skrll #endif
107 1.1 skrll if (i >= dkl.d_npartitions || !dkl.d_partitions[i].p_size) {
108 1.1 skrll return (EPART);
109 1.1 skrll }
110 1.1 skrll dp->part_off = dkl.d_partitions[i].p_offset * dkl.d_secsize;
111 1.1 skrll }
112 1.1 skrll #ifdef DEBUGBUG
113 1.1 skrll if (debug)
114 1.1 skrll printf ("dkopen() ret\n");
115 1.1 skrll #endif
116 1.1 skrll return (0);
117 1.1 skrll }
118 1.1 skrll
119 1.1 skrll int
120 1.1 skrll dkclose(struct open_file *f)
121 1.1 skrll {
122 1.1 skrll dealloc(f->f_devdata, sizeof(struct hppa_dev));
123 1.1 skrll f->f_devdata = NULL;
124 1.1 skrll return 0;
125 1.1 skrll }
126