Sat Mar 5 07:33:59 2016 UTC ()
Don't modify command line buffer but create a copy of the root argument.


(mlelstv)
diff -r1.18 -r1.19 src/sys/arch/evbarm/evbarm/autoconf.c

cvs diff -r1.18 -r1.19 src/sys/arch/evbarm/evbarm/autoconf.c (switch to unified diff)

--- src/sys/arch/evbarm/evbarm/autoconf.c 2014/11/22 11:10:22 1.18
+++ src/sys/arch/evbarm/evbarm/autoconf.c 2016/03/05 07:33:58 1.19
@@ -1,175 +1,193 @@ @@ -1,175 +1,193 @@
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.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
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
50void (*evbarm_device_register)(device_t, void *); 50void (*evbarm_device_register)(device_t, void *);
51void (*evbarm_device_register_post_config)(device_t, void *); 51void (*evbarm_device_register_post_config)(device_t, void *);
52 52
53#ifndef MEMORY_DISK_IS_ROOT 53#ifndef MEMORY_DISK_IS_ROOT
54static int get_device(char *name, device_t *, int *); 54static int get_device(char *name, device_t *, int *);
55static void set_root_device(void); 55static void set_root_device(void);
56#endif 56#endif
57 57
58#ifndef MEMORY_DISK_IS_ROOT 58#ifndef MEMORY_DISK_IS_ROOT
59/* Decode a device name to a major and minor number */ 59/* Decode a device name to a major and minor number */
60 60
61static int 61static int
62get_device(char *name, device_t *dvp, int *partp) 62get_device(char *name, device_t *dvp, int *partp)
63{ 63{
64 int unit, part; 64 int unit, part;
65 char devname[16], *cp; 65 char devname[16], *cp;
66 device_t dv; 66 device_t dv;
67 67
68 if (strncmp(name, "/dev/", 5) == 0) 68 if (strncmp(name, "/dev/", 5) == 0)
69 name += 5; 69 name += 5;
70 70
71 if (devsw_name2blk(name, devname, sizeof(devname)) == -1) 71 if (devsw_name2blk(name, devname, sizeof(devname)) == -1)
72 return 0; 72 return 0;
73 73
74 name += strlen(devname); 74 name += strlen(devname);
75 unit = part = 0; 75 unit = part = 0;
76 76
77 cp = name; 77 cp = name;
78 while (*cp >= '0' && *cp <= '9') 78 while (*cp >= '0' && *cp <= '9')
79 unit = (unit * 10) + (*cp++ - '0'); 79 unit = (unit * 10) + (*cp++ - '0');
80 if (cp == name) 80 if (cp == name)
81 return 0; 81 return 0;
82 82
83 if (*cp >= 'a' && *cp < ('a' + MAXPARTITIONS)) 83 if (*cp >= 'a' && *cp < ('a' + MAXPARTITIONS))
84 part = *cp - 'a'; 84 part = *cp - 'a';
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
 98static char *bootspec_buf = NULL;
 99static size_t bootspec_buflen = 0;
 100
98static void 101static void
99set_root_device(void) 102set_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 */
127void 145void
128cpu_rootconf(void) 146cpu_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",
134 booted_device != NULL ? device_xname(booted_device) : "<unknown>"); 152 booted_device != NULL ? device_xname(booted_device) : "<unknown>");
135 rootconf(); 153 rootconf();
136} 154}
137 155
138 156
139/* 157/*
140 * void cpu_configure() 158 * void cpu_configure()
141 * 159 *
142 * Configure all the root devices 160 * Configure all the root devices
143 * The root devices are expected to configure their own children 161 * The root devices are expected to configure their own children
144 */ 162 */
145void 163void
146cpu_configure(void) 164cpu_configure(void)
147{ 165{
148 struct mainbus_attach_args maa; 166 struct mainbus_attach_args maa;
149 167
150 (void) splhigh(); 168 (void) splhigh();
151 (void) splserial(); /* XXX need an splextreme() */ 169 (void) splserial(); /* XXX need an splextreme() */
152 170
153 maa.ma_name = "mainbus"; 171 maa.ma_name = "mainbus";
154 172
155 config_rootfound("mainbus", &maa); 173 config_rootfound("mainbus", &maa);
156 174
157 /* Time to start taking interrupts so lets open the flood gates .... */ 175 /* Time to start taking interrupts so lets open the flood gates .... */
158 spl0(); 176 spl0();
159} 177}
160 178
161void 179void
162device_register(device_t dev, void *aux) 180device_register(device_t dev, void *aux)
163{ 181{
164 if (evbarm_device_register != NULL) 182 if (evbarm_device_register != NULL)
165 (*evbarm_device_register)(dev, aux); 183 (*evbarm_device_register)(dev, aux);
166} 184}
167 185
168 186
169void 187void
170device_register_post_config(device_t dev, void *aux) 188device_register_post_config(device_t dev, void *aux)
171{ 189{
172 if (evbarm_device_register_post_config != NULL) 190 if (evbarm_device_register_post_config != NULL)
173 (*evbarm_device_register_post_config)(dev, aux); 191 (*evbarm_device_register_post_config)(dev, aux);
174} 192}
175 193