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>
54 fprintf(stderr, "usage: %s [-f device] op...\n", progname);
55 fprintf(stderr, "where op's are:\n");
56 fprintf(stderr, "fact\t\tread factory PR segment\n");
57 fprintf(stderr, "oem\t\tread OEM segment\n");
58 fprintf(stderr, "woem value\twrite OEM segment\n");
59 fprintf(stderr, "plr\t\tread PLR\n");
60 fprintf(stderr, "wplr\t\twrite PLR\n");
67 int fd = open(dvname, mode, 0);
77 int fd = getfd(O_RDONLY);
78 if (ioctl(fd, CFIOCGFACTORYPR, &v) < 0)
79 err(-1, "ioctl(CFIOCGFACTORYPR)");
88 int fd = getfd(O_RDONLY);
89 if (ioctl(fd, CFIOCGOEMPR, &v) < 0)
90 err(-1, "ioctl(CFIOCGOEMPR)");
98 int fd = getfd(O_WRONLY);
99 if (ioctl(fd, CFIOCSOEMPR, &v) < 0)
100 err(-1, "ioctl(CFIOCGOEMPR)");
108 int fd = getfd(O_RDONLY);
109 if (ioctl(fd, CFIOCGPLR, &plr) < 0)
110 err(-1, "ioctl(CFIOCGPLR)");
118 int fd = getfd(O_WRONLY);
119 if (ioctl(fd, CFIOCSPLR, 0) < 0)
120 err(-1, "ioctl(CFIOCPLR)");
125 main(int argc, char *argv[])
127 dvname = getenv("CFI");
129 dvname = "/dev/cfi0";
132 if (strcmp(argv[1], "-f") == 0) {
134 errx(1, "missing device name for -f option");
136 argc -= 2, argv += 2;
137 } else if (strcmp(argv[1], "-?") == 0)
140 for (; argc > 1; argc--, argv++) {
141 if (strcasecmp(argv[1], "fact") == 0) {
142 printf("0x%llx\n", (unsigned long long) getfactorypr());
143 } else if (strcasecmp(argv[1], "oem") == 0) {
144 printf("0x%llx\n", (unsigned long long) getoempr());
145 } else if (strcasecmp(argv[1], "woem") == 0) {
147 errx(1, "missing value for woem");
148 setoempr((uint64_t) strtoull(argv[2], NULL, 0));
150 } else if (strcasecmp(argv[1], "plr") == 0) {
151 printf("0x%x\n", getplr());
152 } else if (strcasecmp(argv[1], "wplr") == 0) {