1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
/* $OpenBSD: main.c,v 1.17 2007/11/14 20:38:32 kettenis Exp $ */
/* $NetBSD: main.c,v 1.3 1996/05/16 16:00:55 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/param.h>
#include <err.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#if defined(__sparc__) && !defined(__sparc64__)
#include <fcntl.h>
#include <limits.h>
#include <sys/sysctl.h>
#include <machine/cpu.h>
#include <machine/eeprom.h>
#endif /* __sparc__ && !__sparc64__ */
#include <machine/openpromio.h>
#include "defs.h"
#if defined(__sparc__) && !defined(__sparc64__)
static char *nlistf = NULL;
struct keytabent eekeytab[] = {
{ "hwupdate", 0x10, ee_hwupdate },
{ "memsize", 0x14, ee_num8 },
{ "memtest", 0x15, ee_num8 },
{ "scrsize", 0x16, ee_screensize },
{ "watchdog_reboot", 0x17, ee_truefalse },
{ "default_boot", 0x18, ee_truefalse },
{ "bootdev", 0x19, ee_bootdev },
{ "kbdtype", 0x1e, ee_kbdtype },
{ "console", 0x1f, ee_constype },
{ "keyclick", 0x21, ee_truefalse },
{ "diagdev", 0x22, ee_bootdev },
{ "diagpath", 0x28, ee_diagpath },
{ "columns", 0x50, ee_num8 },
{ "rows", 0x51, ee_num8 },
{ "ttya_use_baud", 0x58, ee_truefalse },
{ "ttya_baud", 0x59, ee_num16 },
{ "ttya_no_rtsdtr", 0x5b, ee_truefalse },
{ "ttyb_use_baud", 0x60, ee_truefalse },
{ "ttyb_baud", 0x61, ee_num16 },
{ "ttyb_no_rtsdtr", 0x63, ee_truefalse },
{ "banner", 0x68, ee_banner },
{ "secure", 0, ee_notsupp },
{ "bad_login", 0, ee_notsupp },
{ "password", 0, ee_notsupp },
{ NULL, 0, ee_notsupp },
};
#endif /* __sparc__ && !__sparc64__ */
static void action(char *);
static void dump_prom(void);
static void usage(void);
#if defined(__sparc__) && !defined(__sparc64__)
static int getcputype(void);
#endif /* __sparc__ && !__sparc64__ */
char *path_eeprom = "/dev/eeprom";
char *path_openprom = "/dev/openprom";
int fix_checksum = 0;
int ignore_checksum = 0;
int update_checksums = 0;
int cksumfail = 0;
u_short writecount;
int eval = 0;
int use_openprom = 0;
int print_tree = 0;
int verbose = 0;
extern char *__progname;
int
main(int argc, char *argv[])
{
int ch, do_stdin = 0;
char *cp, line[BUFSIZE];
gid_t gid;
char *optstring = "cf:ipvN:-";
while ((ch = getopt(argc, argv, optstring)) != -1)
switch (ch) {
case '-':
do_stdin = 1;
break;
case 'c':
fix_checksum = 1;
break;
case 'f':
path_eeprom = path_openprom = optarg;
break;
case 'i':
ignore_checksum = 1;
break;
case 'p':
print_tree = 1;
break;
case 'v':
verbose = 1;
break;
#if defined(__sparc__) && !defined(__sparc64__)
case 'N':
nlistf = optarg;
break;
#endif /* __sparc__ && !__sparc64__ */
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
#if defined(__sparc__) && !defined(__sparc64__)
if (nlistf != NULL) {
gid = getgid();
if (setresgid(gid, gid, gid) == -1)
err(1, "setresgid");
}
if (getcputype() != CPU_SUN4)
#endif /* __sparc__ && !__sparc64__ */
use_openprom = 1;
if (print_tree && use_openprom) {
op_tree();
exit(0);
}
#if defined(__sparc__) && !defined(__sparc64__)
if (use_openprom == 0) {
ee_verifychecksums();
if (fix_checksum || cksumfail)
exit(cksumfail);
}
#endif /* __sparc__ && !__sparc64__ */
if (do_stdin) {
while (fgets(line, BUFSIZE, stdin) != NULL) {
if (line[0] == '\n')
continue;
if ((cp = strrchr(line, '\n')) != NULL)
*cp = '\0';
action(line);
}
if (ferror(stdin))
err(++eval, "stdin");
} else {
if (argc == 0) {
dump_prom();
exit(eval + cksumfail);
}
while (argc) {
action(*argv);
++argv;
--argc;
}
}
#if defined(__sparc__) && !defined(__sparc64__)
if (use_openprom == 0)
if (update_checksums) {
++writecount;
ee_updatechecksums();
}
#endif /* __sparc__ && !__sparc64__ */
exit(eval + cksumfail);
}
#if defined(__sparc__) && !defined(__sparc64__)
static int
getcputype(void)
{
int mib[2];
size_t len;
int cputype;
mib[0] = CTL_MACHDEP;
mib[1] = CPU_CPUTYPE;
len = sizeof(cputype);
if (sysctl(mib, 2, &cputype, &len, NULL, 0) < 0)
err(1, "sysctl(machdep.cputype)");
return (cputype);
}
#endif /* __sparc__ && !__sparc64__ */
/*
* Separate the keyword from the argument (if any), find the keyword in
* the table, and call the corresponding handler function.
*/
static void
action(char *line)
{
char *keyword, *arg, *cp;
struct keytabent *ktent;
keyword = strdup(line);
if (!keyword)
errx(1, "out of memory");
if ((arg = strrchr(keyword, '=')) != NULL)
*arg++ = '\0';
if (use_openprom) {
/*
* The whole point of the Openprom is that one
* isn't required to know the keywords. With this
* in mind, we just dump the whole thing off to
* the generic op_handler.
*/
if ((cp = op_handler(keyword, arg)) != NULL)
warnx("%s", cp);
return;
}
#if defined(__sparc__) && !defined(__sparc64__)
else
for (ktent = eekeytab; ktent->kt_keyword != NULL; ++ktent) {
if (strcmp(ktent->kt_keyword, keyword) == 0) {
(*ktent->kt_handler)(ktent, arg);
return;
}
}
#endif /* __sparc__ && !__sparc64__ */
warnx("unknown keyword %s", keyword);
++eval;
}
/*
* Dump the contents of the prom corresponding to all known keywords.
*/
static void
dump_prom(void)
{
struct keytabent *ktent;
if (use_openprom) {
/*
* We have a special dump routine for this.
*/
op_dump();
}
#if defined(__sparc__) && !defined(__sparc64__)
else
for (ktent = eekeytab; ktent->kt_keyword != NULL; ++ktent)
(*ktent->kt_handler)(ktent, NULL);
#endif /* __sparc__ && !__sparc64__ */
}
static void
usage(void)
{
#if defined(__sparc__) && !defined(__sparc64__)
fprintf(stderr,
"usage: %s [-cipv] [-f device] [-N system] [field[=value] ...]\n",
__progname);
#else
fprintf(stderr,
"usage: %s [-cipv] [-f device] [field[=value] ...]\n",
__progname);
#endif /* __sparc__ && !__sparc64__ */
exit(1);
}
|