| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: autoconf.c,v 1.18 2014/11/22 11:10:22 mlelstv Exp $ */ | | 1 | /* $NetBSD: autoconf.c,v 1.19 2016/03/05 07:33:58 mlelstv Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2001 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2001 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Matt Thomas <matt@3am-software.com>. | | 8 | * by Matt Thomas <matt@3am-software.com>. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -20,38 +20,38 @@ | | | @@ -20,38 +20,38 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.18 2014/11/22 11:10:22 mlelstv Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.19 2016/03/05 07:33:58 mlelstv Exp $"); |
34 | | | 34 | |
35 | #include "opt_md.h" | | 35 | #include "opt_md.h" |
36 | | | 36 | |
37 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
38 | #include <sys/systm.h> | | 38 | #include <sys/systm.h> |
39 | #include <sys/reboot.h> | | 39 | #include <sys/reboot.h> |
40 | #include <sys/disklabel.h> | | 40 | #include <sys/disklabel.h> |
41 | #include <sys/device.h> | | 41 | #include <sys/device.h> |
42 | #include <sys/conf.h> | | 42 | #include <sys/conf.h> |
43 | #include <sys/kernel.h> | | 43 | #include <sys/kernel.h> |
44 | #include <sys/malloc.h> | | 44 | #include <sys/kmem.h> |
45 | | | 45 | |
46 | #include <machine/autoconf.h> | | 46 | #include <machine/autoconf.h> |
47 | #include <machine/intr.h> | | 47 | #include <machine/intr.h> |
48 | #include <machine/bootconfig.h> | | 48 | #include <machine/bootconfig.h> |
49 | | | 49 | |
50 | void (*evbarm_device_register)(device_t, void *); | | 50 | void (*evbarm_device_register)(device_t, void *); |
51 | void (*evbarm_device_register_post_config)(device_t, void *); | | 51 | void (*evbarm_device_register_post_config)(device_t, void *); |
52 | | | 52 | |
53 | #ifndef MEMORY_DISK_IS_ROOT | | 53 | #ifndef MEMORY_DISK_IS_ROOT |
54 | static int get_device(char *name, device_t *, int *); | | 54 | static int get_device(char *name, device_t *, int *); |
55 | static void set_root_device(void); | | 55 | static void set_root_device(void); |
56 | #endif | | 56 | #endif |
57 | | | 57 | |
| @@ -85,49 +85,67 @@ get_device(char *name, device_t *dvp, in | | | @@ -85,49 +85,67 @@ get_device(char *name, device_t *dvp, in |
85 | else if (*cp != '\0' && *cp != ' ') | | 85 | else if (*cp != '\0' && *cp != ' ') |
86 | return 0; | | 86 | return 0; |
87 | if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) { | | 87 | if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) { |
88 | *dvp = dv; | | 88 | *dvp = dv; |
89 | *partp = part; | | 89 | *partp = part; |
90 | return 1; | | 90 | return 1; |
91 | } | | 91 | } |
92 | | | 92 | |
93 | return 0; | | 93 | return 0; |
94 | } | | 94 | } |
95 | | | 95 | |
96 | /* Set the rootdev variable from the root specifier in the boot args */ | | 96 | /* Set the rootdev variable from the root specifier in the boot args */ |
97 | | | 97 | |
| | | 98 | static char *bootspec_buf = NULL; |
| | | 99 | static size_t bootspec_buflen = 0; |
| | | 100 | |
98 | static void | | 101 | static void |
99 | set_root_device(void) | | 102 | set_root_device(void) |
100 | { | | 103 | { |
101 | char *ptr, *end; | | 104 | char *ptr, *end, *buf; |
| | | 105 | size_t len; |
102 | | | 106 | |
103 | if (boot_args == NULL) | | 107 | if (boot_args == NULL) |
104 | return; | | 108 | return; |
105 | | | 109 | |
106 | if (!get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr)) | | 110 | if (!get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr)) |
107 | return; | | 111 | return; |
108 | | | 112 | |
109 | if (get_device(ptr, &booted_device, &booted_partition)) | | 113 | if (get_device(ptr, &booted_device, &booted_partition)) |
110 | return; | | 114 | return; |
111 | | | 115 | |
112 | /* NUL-terminate string, get_bootconf_option doesn't */ | | 116 | /* NUL-terminate string, get_bootconf_option doesn't */ |
113 | for (end=ptr; *end != '\0'; ++end) { | | 117 | for (end=ptr; *end != '\0'; ++end) { |
114 | if (*end == ' ' || *end == '\t') { | | 118 | if (*end == ' ' || *end == '\t') { |
115 | *end = '\0'; | | | |
116 | break; | | 119 | break; |
117 | } | | 120 | } |
118 | } | | 121 | } |
119 | | | 122 | |
120 | bootspec = ptr; | | 123 | if (end == ptr) |
| | | 124 | return; |
| | | 125 | |
| | | 126 | len = end - ptr; |
| | | 127 | |
| | | 128 | buf = kmem_alloc(len + 1, KM_SLEEP); |
| | | 129 | memcpy(buf, ptr, len); |
| | | 130 | buf[len] = '\0'; |
| | | 131 | |
| | | 132 | if (bootspec_buf != NULL) |
| | | 133 | kmem_free(bootspec_buf, bootspec_buflen + 1); |
| | | 134 | |
| | | 135 | bootspec_buf = buf; |
| | | 136 | bootspec_buflen = len; |
| | | 137 | |
| | | 138 | bootspec = bootspec_buf; |
121 | } | | 139 | } |
122 | #endif | | 140 | #endif |
123 | | | 141 | |
124 | /* | | 142 | /* |
125 | * Set up the root device from the boot args | | 143 | * Set up the root device from the boot args |
126 | */ | | 144 | */ |
127 | void | | 145 | void |
128 | cpu_rootconf(void) | | 146 | cpu_rootconf(void) |
129 | { | | 147 | { |
130 | #ifndef MEMORY_DISK_IS_ROOT | | 148 | #ifndef MEMORY_DISK_IS_ROOT |
131 | set_root_device(); | | 149 | set_root_device(); |
132 | #endif | | 150 | #endif |
133 | aprint_normal("boot device: %s\n", | | 151 | aprint_normal("boot device: %s\n", |