1 /* $NetBSD: main.c,v 1.20 2009/04/26 01:51:07 lukem Exp $ */
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
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
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 __COPYRIGHT("@(#) Copyright (c) 1996\
35 The NetBSD Foundation, Inc. All rights reserved.");
36 __RCSID("$NetBSD: main.c,v 1.20 2009/04/26 01:51:07 lukem Exp $");
39 #include <sys/param.h>
47 #include <machine/eeprom.h>
51 #include "pathnames.h"
53 #if defined(__sparc__)
55 # if defined(__arch64__)
56 # define ee_action(a,b)
58 # define ee_updatechecksums() (void)0
59 # define check_for_openprom() 1
63 int main (int, char *[]);
64 static void action (char *);
65 static void dump_prom (void);
66 static void usage (void);
68 const char *path_eeprom
= _PATH_EEPROM
;
69 const char *path_openprom
= _PATH_OPENPROM
;
70 const char *path_openfirm
= _PATH_OPENFIRM
;
71 const char *path_prepnvram
= _PATH_PREPNVRAM
;
73 int ignore_checksum
= 0;
74 int update_checksums
= 0;
82 #if defined(USE_OPENFIRM) || defined (USE_PREPNVRAM)
92 char *cp
, line
[BUFSIZE
];
93 #if defined(USE_OPENPROM) || defined(USE_OPENFIRM) || defined(USE_PREPNVRAM)
94 const char *optstring
= "-cf:iv";
96 const char *optstring
= "-cf:i";
97 #endif /* USE_OPENPROM */
99 while ((ch
= getopt(argc
, argv
, optstring
)) != -1)
110 path_eeprom
= path_openprom
= optarg
;
117 #if defined(USE_OPENPROM) || defined(USE_OPENFIRM) || defined(USE_PREPNVRAM)
121 #endif /* USE_OPENPROM */
131 use_openprom
= check_for_openprom();
133 if (use_openprom
== 0) {
134 #endif /* USE_OPENPROM */
135 #if !defined(USE_OPENFIRM) && !defined(USE_PREPNVRAM)
136 ee_verifychecksums();
137 if (fix_checksum
|| cksumfail
)
142 #endif /* USE_OPENPROM */
145 while (fgets(line
, BUFSIZE
, stdin
) != NULL
) {
148 if ((cp
= strrchr(line
, '\n')) != NULL
)
153 err(++eval
, "stdin");
157 exit(eval
+ cksumfail
);
168 if (use_openprom
== 0)
169 #endif /* USE_OPENPROM */
170 #if !defined(USE_OPENFIRM) && !defined(USE_PREPNVRAM)
171 if (update_checksums
) {
173 ee_updatechecksums();
176 exit(eval
+ cksumfail
);
182 * Separate the keyword from the argument (if any), find the keyword in
183 * the table, and call the corresponding handler function.
191 keyword
= strdup(line
);
192 if ((arg
= strrchr(keyword
, '=')) != NULL
)
196 prep_action(keyword
, arg
);
199 of_action(keyword
, arg
);
203 op_action(keyword
, arg
);
205 #endif /* USE_OPENPROM */
206 ee_action(keyword
, arg
);
209 #endif /* USE_OPENPROM */
210 #endif /* USE_OPENFIRM */
211 #endif /* USE_PREPNVRAM */
215 * Dump the contents of the prom corresponding to all known keywords.
230 * We have a special dump routine for this.
234 #endif /* USE_OPENPROM */
238 #endif /* USE_OPENPROM */
239 #endif /* USE_OPENFIRM */
240 #endif /* USE_PREPNVRAM */
247 #if defined(USE_OPENPROM) || defined(USE_OPENFIRM) || defined(USE_PREPNVRAM)
248 fprintf(stderr
, "usage: %s %s\n", getprogname(),
249 "[-] [-c] [-f device] [-i] [-v] [field[=value] ...]");
251 fprintf(stderr
, "usage: %s %s\n", getprogname(),
252 "[-] [-c] [-f device] [-i] [field[=value] ...]");