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