devopen.c revision 1.1.2.2 1 1.1.2.2 skrll /* $NetBSD: devopen.c,v 1.1.2.2 2017/02/05 13:40:12 skrll Exp $ */
2 1.1.2.2 skrll
3 1.1.2.2 skrll /*-
4 1.1.2.2 skrll * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 1.1.2.2 skrll * All rights reserved.
6 1.1.2.2 skrll *
7 1.1.2.2 skrll * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 skrll * by Bang Jun-Young.
9 1.1.2.2 skrll *
10 1.1.2.2 skrll * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 skrll * modification, are permitted provided that the following conditions
12 1.1.2.2 skrll * are met:
13 1.1.2.2 skrll * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 skrll * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 skrll * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 skrll * documentation and/or other materials provided with the distribution.
18 1.1.2.2 skrll *
19 1.1.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.2.2 skrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.2.2 skrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.2.2 skrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.2.2 skrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.2.2 skrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.2.2 skrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.2.2 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.2.2 skrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.2.2 skrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.2.2 skrll * POSSIBILITY OF SUCH DAMAGE.
30 1.1.2.2 skrll */
31 1.1.2.2 skrll
32 1.1.2.2 skrll /*
33 1.1.2.2 skrll * Copyright (c) 1996, 1997
34 1.1.2.2 skrll * Matthias Drochner. All rights reserved.
35 1.1.2.2 skrll *
36 1.1.2.2 skrll * Redistribution and use in source and binary forms, with or without
37 1.1.2.2 skrll * modification, are permitted provided that the following conditions
38 1.1.2.2 skrll * are met:
39 1.1.2.2 skrll * 1. Redistributions of source code must retain the above copyright
40 1.1.2.2 skrll * notice, this list of conditions and the following disclaimer.
41 1.1.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
42 1.1.2.2 skrll * notice, this list of conditions and the following disclaimer in the
43 1.1.2.2 skrll * documentation and/or other materials provided with the distribution.
44 1.1.2.2 skrll *
45 1.1.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
46 1.1.2.2 skrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 1.1.2.2 skrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48 1.1.2.2 skrll * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
49 1.1.2.2 skrll * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 1.1.2.2 skrll * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
51 1.1.2.2 skrll * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
52 1.1.2.2 skrll * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
53 1.1.2.2 skrll * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
54 1.1.2.2 skrll * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 1.1.2.2 skrll */
56 1.1.2.2 skrll
57 1.1.2.2 skrll #include "efiboot.h"
58 1.1.2.2 skrll
59 1.1.2.2 skrll #include <biosdisk.h>
60 1.1.2.2 skrll #include "devopen.h"
61 1.1.2.2 skrll #include <bootinfo.h>
62 1.1.2.2 skrll
63 1.1.2.2 skrll static int
64 1.1.2.2 skrll dev2bios(char *devname, int unit, int *biosdev)
65 1.1.2.2 skrll {
66 1.1.2.2 skrll
67 1.1.2.2 skrll if (strcmp(devname, "hd") == 0)
68 1.1.2.2 skrll *biosdev = 0x80 + unit;
69 1.1.2.2 skrll else
70 1.1.2.2 skrll return ENXIO;
71 1.1.2.2 skrll return 0;
72 1.1.2.2 skrll }
73 1.1.2.2 skrll
74 1.1.2.2 skrll void
75 1.1.2.2 skrll bios2dev(int biosdev, daddr_t sector, char **devname, int *unit, int *partition)
76 1.1.2.2 skrll {
77 1.1.2.2 skrll
78 1.1.2.2 skrll *unit = biosdev & 0x7f;
79 1.1.2.2 skrll *devname = "hd";
80 1.1.2.2 skrll *partition = biosdisk_findpartition(biosdev, sector);
81 1.1.2.2 skrll }
82 1.1.2.2 skrll
83 1.1.2.2 skrll struct btinfo_bootpath bibp;
84 1.1.2.2 skrll extern bool kernel_loaded;
85 1.1.2.2 skrll
86 1.1.2.2 skrll /*
87 1.1.2.2 skrll * Open the EFI disk device
88 1.1.2.2 skrll */
89 1.1.2.2 skrll int
90 1.1.2.2 skrll devopen(struct open_file *f, const char *fname, char **file)
91 1.1.2.2 skrll {
92 1.1.2.2 skrll char *fsname, *devname;
93 1.1.2.2 skrll int unit, partition;
94 1.1.2.2 skrll int biosdev;
95 1.1.2.2 skrll int error;
96 1.1.2.2 skrll
97 1.1.2.2 skrll if ((error = parsebootfile(fname, &fsname, &devname,
98 1.1.2.2 skrll &unit, &partition, (const char **) file))
99 1.1.2.2 skrll || (error = dev2bios(devname, unit, &biosdev)))
100 1.1.2.2 skrll return error;
101 1.1.2.2 skrll
102 1.1.2.2 skrll f->f_dev = &devsw[0]; /* must be biosdisk */
103 1.1.2.2 skrll
104 1.1.2.2 skrll if (!kernel_loaded) {
105 1.1.2.2 skrll strncpy(bibp.bootpath, *file, sizeof(bibp.bootpath));
106 1.1.2.2 skrll BI_ADD(&bibp, BTINFO_BOOTPATH, sizeof(bibp));
107 1.1.2.2 skrll }
108 1.1.2.2 skrll
109 1.1.2.2 skrll return biosdisk_open(f, biosdev, partition);
110 1.1.2.2 skrll }
111