2 * Copyright (c) 2009 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
34 * (default device is /dev/cfi0).
36 #include <sys/types.h>
38 #include <sys/ioctl.h>
39 #include <sys/cfictl.h>
53 fprintf(stderr, "usage: %s [-f device] op...\n", progname);
54 fprintf(stderr, "where op's are:\n");
55 fprintf(stderr, "fact\t\tread factory PR segment\n");
56 fprintf(stderr, "oem\t\tread OEM segment\n");
57 fprintf(stderr, "woem value\twrite OEM segment\n");
58 fprintf(stderr, "plr\t\tread PLR\n");
59 fprintf(stderr, "wplr\t\twrite PLR\n");
66 int fd = open(dvname, mode, 0);
76 int fd = getfd(O_RDONLY);
77 if (ioctl(fd, CFIOCGFACTORYPR, &v) < 0)
78 err(-1, "ioctl(CFIOCGFACTORYPR)");
87 int fd = getfd(O_RDONLY);
88 if (ioctl(fd, CFIOCGOEMPR, &v) < 0)
89 err(-1, "ioctl(CFIOCGOEMPR)");
97 int fd = getfd(O_WRONLY);
98 if (ioctl(fd, CFIOCSOEMPR, &v) < 0)
99 err(-1, "ioctl(CFIOCGOEMPR)");
107 int fd = getfd(O_RDONLY);
108 if (ioctl(fd, CFIOCGPLR, &plr) < 0)
109 err(-1, "ioctl(CFIOCGPLR)");
117 int fd = getfd(O_WRONLY);
118 if (ioctl(fd, CFIOCSPLR, 0) < 0)
119 err(-1, "ioctl(CFIOCPLR)");
124 main(int argc, char *argv[])
126 dvname = getenv("CFI");
128 dvname = "/dev/cfi0";
131 if (strcmp(argv[1], "-f") == 0) {
133 errx(1, "missing device name for -f option");
135 argc -= 2, argv += 2;
136 } else if (strcmp(argv[1], "-?") == 0)
139 for (; argc > 1; argc--, argv++) {
140 if (strcasecmp(argv[1], "fact") == 0) {
141 printf("0x%llx\n", (unsigned long long) getfactorypr());
142 } else if (strcasecmp(argv[1], "oem") == 0) {
143 printf("0x%llx\n", (unsigned long long) getoempr());
144 } else if (strcasecmp(argv[1], "woem") == 0) {
146 errx(1, "missing value for woem");
147 setoempr((uint64_t) strtoull(argv[2], NULL, 0));
149 } else if (strcasecmp(argv[1], "plr") == 0) {
150 printf("0x%x\n", getplr());
151 } else if (strcasecmp(argv[1], "wplr") == 0) {